SQLServerÖÐDatetimeÀàÐÍÊý¾ÝµÄ±È½Ï
SQLServerÖÐDatetimeÀàÐÍÊý¾ÝµÄ±È½Ï
2009Äê02ÔÂ20ÈÕ ÐÇÆÚÎå 16:40
/* ¶¨Ò忪ʼÈÕÆÚºÍ½áÊøÈÕÆÚ*/
declare @date_a datetime,@date_b datetime
set @date_a='2009-2-10'
set @date_b='2009-2-12'
/* ÔÚÈÕÆÚdate_a(°üº¬) ºÍdate_b(²»°üº¬) Ö®¼ä*/
select * from ut_article where createtime between @date_a and @date_b
/* ÔÚÈÕÆÚdate_a(²»°üº¬) ºÍdate_b(°üº¬) Ö®¼ä*/
select * from ut_article where datediff(d,@date_a,createtime)>0 and datediff(d,@date_b,createtime)<=0
/* ÔÚÈÕÆÚdate_a(²»°üº¬) ºÍdate_b(²»°üº¬) Ö®¼ä*/
select * from ut_article where datediff(d,@date_a,createtime)>0 and datediff(d,@date_b,createtime)<0
/* ÔÚÈÕÆÚdate_a(°üº¬) ºÍdate_b(°üº¬) Ö®¼ä*/
select * from ut_article where datediff(d,@date_a,createtime)>=0 and datediff(d,@date_b,createtime)<=0
Ïà¹ØÎĵµ£º
-- ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ
¼ÓÄê·Ý——print dateadd(year, 5, getdate()) ¼ÓÔ·ݗ—print dateadd(month, 5, getdate())
¼ÓÌìÊý——print dateadd(day, 5, getdate()) ¼ÓСʱ——print dat ......
¹«Ë¾×éÖ¯SQLˮƽ¿¼ÊÔ£¬¿´ÁËд½Ì²Ä£¬Ð´Á˵ã×ܽᷢÉÏÀ´¸ú´ó¼Ò·ÖÏí¡£
ÎÒ¹«Ë¾Ê¹ÓõÄÊÇSybase ASE12.5£¬ËùÒÔÏÂÃæµÄÒ»Ð©ÌØÐÔÊÇÕë¶ÔSybase ASEµÄ¡£
Ò»£ºSQL Bisic
1£ºSQL(Structured Quary Language)ÌØÐÔ£º
a£º±ê×¼»¯
b£º·Ç¹ý³Ì»¯µÄ
c£º¿ÉÓÅ»¯µÄ
d£ºÃæÏò¼¯ºÏ²Ù×÷µÄ
2£ºASEÖеÄÊý¾ÝÀàÐÍ
a£ºNumberic
b£ºCharacter
c£ºDa ......
Mysql£¬SqlServer£¬OracleÖ÷¼ü×Ô¶¯Ôö³¤µÄÉèÖÃ
1¡¢°ÑÖ÷¼ü¶¨ÒåΪ×Ô¶¯Ôö³¤±êʶ·ûÀàÐÍ
ÔÚmysqlÖУ¬Èç¹û°Ñ±íµÄÖ÷¼üÉèΪauto_incrementÀàÐÍ£¬Êý¾Ý¿â¾Í»á×Ô¶¯ÎªÖ÷¼ü¸³Öµ¡£ÀýÈ磺
create table customers(id int auto_increment primary key not null, name varchar(15));
insert into customers(name) values("name1"),("nam ......
¸ù¾Ý±í½á¹¹Éú³ÉJavaÎļþµÄ¹¤¾ß£¬ÔÚÈ¡µÃ±íµÄ×Ö¶ÎʱÈçºÎÈ¡µÃ±íµÄ¸÷ÖÖÐÅÏ¢ºÍ×¢ÊÍ£¬¾¶à·½ËÑѰÕÒµ½ÈçÏÂ×ÊÁϱ¸Ó㺠oracle£º
user_tab_comments;±í×¢ÊÍ
user_col_comments;±í×Ö¶Î×¢ÊÍ
Ò ......
Êý¾ÝÀï(sqlserver) µÄ²Ù×÷ £º
eg £º2008-3-31 10:34 --> 2008-3-31
Ò».½ØÈ¡×Ö·û´®·½Ê½
select substring('2008-3-31 10:34',0,charindex(' ','2008-3-31 10:34'))
¶þ.
Select
CONVERT(varchar, getdate(), 1),--mm/dd/yy
CONVERT(varchar, getdate(), 2),--yy.mm.dd
CONVERT(varchar, getdate() ......