SQL日期时间函数大全 Sql Server中的日期与时间函数
来源:互联网 发布:js array的方法和属性 编辑:程序博客网 时间:2024/04/29 19:19
1. 当前系统日期、时间 /u0011F桗?赝Q?
select getdate() /u0017鈙H /u0018倂建
鶞Oh牧/"葵
2. dateadd 在向指定日期加上一段时间的基础上,返回新的 datetime 值 r鯔俏?/u001C?
例如:向日期加上2天 ?5皴?/u001E煃
select dateadd(day,2,'2004-10-15') --返回:2004-10-17 00:00:00.000 /u001CEw郬*矝?
?礛娞>??
3. datediff 返回跨两个指定日期的日期和时间边界数。 jo/u0006u/u0018秙 溽
select datediff(day,'2004-09-01','2004-09-18') --返回:17 ?鼄G驂W
/u001D毰筒???
4. datepart 返回代表指定日期的指定日期部分的整数。 劸赔D///穙
SELECT DATEPART(month, '2004-10-15') --返回 10 Rk銍倝K$7$
欤晛u!:/u001A?
5. datename 返回代表指定日期的指定日期部分的字符串 堼梶 U咙
SELECT datename(weekday, '2004-10-15') --返回:星期五 S吜瞎d湺
'茜?鈠6
6. day(), month(),year() --可以与datepart对照一下 V?u罞戀/m
/u0006?/u0014HZ?S/u001A
select 当前日期=convert(varchar(10),getdate(),120) s1 /u0011喨??
,当前时间=convert(varchar(8),getdate(),114) 即N屾蛶4
抗栳B銫K'/
select datename(dw,'2004-10-15') ?3慯萳籋?
b?| /u0004
select 本年第多少周=datename(week,'2004-10-15') 宎梯d/u0010<短?
,今天是周几=datename(weekday,'2004-10-15') 牶/u0016?1嶙挈
鱒聈W]?n
奄<8姓婨?
函数 参数/功能 /u0013y?/u0011蓦??
GetDate( ) 返回系统目前的日期与时间 '瞫濾#縶?
DateDiff (interval,date1,date2) 以interval 指定的方式,返回date2 与date1两个日期之间的差值 date2-date1 鸊脺 儔砍?
DateAdd (interval,number,date) 以interval指定的方式,加上number之后的日期 "?Ke蠅5流
DatePart (interval,date) 返回日期date中,interval指定部分所对应的整数值 鑒/蟉错渥/u0011
DateName (interval,date) 返回日期date中,interval指定部分所对应的字符串名称 杶逯/u0002夤脅c
呓h/u0012:l=?
参数 interval的设定值如下: 掅/u0018YW/u0013@鲫=
/u00188?濠/u001A?
值 缩 写(Sql Server) (Access 和 ASP) 说明 /u000E蔟/u0006T)軤
Year Yy yyyy 年 1753 ~ 9999 A玍癣0qg /u0017
Quarter Qq q 季 1 ~ 4 駨#伥沠?F;
Month Mm m 月1 ~ 12 O?c(a耀蒪
Day of year Dy y 一年的日数,一年中的第几日 1-366 Y/u0004觲挰/u0015褽/u000F
Day Dd d 日,1-31 粤茎綪嶴诳
Weekday Dw w 一周的日数,一周中的第几日 1-7 襪齀/u0019& ?
Week Wk ww 周,一年中的第几周 0 ~ 51 ?X葤7/u0006膧/u001C
Hour Hh h 时0 ~ 23 F?F啇U暜?
Minute Mi n 分钟0 ~ 59 貞』~r笍o
Second Ss s 秒 0 ~ 59 ?6Y?";d
Millisecond Ms - 毫秒 0 ~ 999 AQ彩堐?E8
?闪潽麘缂
Ъ@p彰t3?
access 和 asp 中用date()和now()取得系统日期时间;其中DateDiff,DateAdd,DatePart也同是能用于Access和asp中,这些函数的用法也类似 /u000E畵?b'?
HLu阏p缤
举例: /0R符?氦?
1.GetDate() 用于sql server :select GetDate() 邊象4/u001D面?
/u0017X"g#/u000F$逹
2.DateDiff('s','2005-07-20','2005-7-25 22:56:32')返回值为 514592 秒 O侠/u0007札⒚
DateDiff('d','2005-07-20','2005-7-25 22:56:32')返回值为 5 天 倮KiC伅嬟/u0004
v?鐜[?觬
3.DatePart('w','2005-7-25 22:56:32')返回值为 2 即星期一(周日为1,周六为7) /u0012?聕qV0?
DatePart('d','2005-7-25 22:56:32')返回值为 25即25号 y萱1雍破?
DatePart('y','2005-7-25 22:56:32')返回值为 206即这一年中第206天 髄??驐?
DatePart('yyyy','2005-7-25 22:56:32')返回值为 2005即2005年
- SQL日期时间函数大全 Sql Server中的日期与时间函数
- Sql Server 中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- Sql Server中的日期与时间函数
- asp DateDiff函数运用
- How to change software UI language
- asp 三级数据库联动下拉列表
- 利用视频文件光端机制造电子查巡系统
- S3C2410支持64M到1GB的NAND FLASH
- SQL日期时间函数大全 Sql Server中的日期与时间函数
- HTTP 状态代码
- 无奈的80人
- 寻找更快的内存拷贝方式
- 没法活了
- linux swap分区大小
- 什么是DOM (转帖)
- sqlserver常用函数/存储过程/数据库角色 收藏
- SQL2000数据库自动备份设置方法。