datetime使用

1天内:convert(varchar(10),posttime,120) = '2010-04-03' 或 Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16

1月内:convert(varchar(7),posttime,120) = '2010-07'

一段日期内:convert(varchar(10),日期列,120) between  时间变量 and  时间变量

convert(varchar,dates,112)     20110501

convert(varchar(6),dates,112)  201105

 

datediff(分钟/秒,201105010901,201105010903)  值是2

yyyy 年
 q     季
 m    月
 y     一年的日数
 d    日
 w    一周的日数
ww  周
 h    时
n    分钟
 s    秒

 

 

 

 

cast(convert(varchar,dates,112) as int)  值20110602       

 year(dates)*10000+month(dates)*100+day(day)  值20110602 

posted @ 2011-02-28 10:35  emmy  阅读(151)  评论(0编辑  收藏  举报