日期函数和字符串函数

日期函数和字符串函数

ID:14140092

大小:40.50 KB

页数:17页

时间:2018-07-26

日期函数和字符串函数_第1页
日期函数和字符串函数_第2页
日期函数和字符串函数_第3页
日期函数和字符串函数_第4页
日期函数和字符串函数_第5页
资源描述:

《日期函数和字符串函数》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、日期函数和字符串函数我寄愁心与明月,随风直到夜郎西。思家步月清宵立,忆弟看云白日眠。为有牺牲多壮志,敢教日月换新天。鹬蚌相争,渔翁得利。风暖鸟声碎,日高花影重。日期函数getdate()得到当前时间,可以设置得到各种时间格式.datepart(日期部分,日期)取指定时间的某一个部分,年月天时分秒.datediff(日期部分,日期1,日期2)计算指定的日期1和日期2的时间差多少.dateadd(日期部分,数值表达式,日期)计算指定时间,再加上表达式指定的时间长度.--取时间的某一个部分selectdatepart(yy,getdate())--yearselectdatepart

2、(mm,getdate())--monthselectdatepart(dd,getdate())--dayselectdatepart(hh,getdate())--hourselectdatepart(mi,getdate())--minselectdatepart(ss,getdate())--sec--取星期几setdatefirst1selectdatepart(weekday,getdate())--weekday--字符串时间selectgetdate()--'03/11/12'selectconvert(char,getdate(),101)--'09/27/2

3、003'selectconvert(char,getdate(),102)--'2003.11.12'selectconvert(char,getdate(),103)--'27/09/2003'selectconvert(char,getdate(),104)--'27.09.2003'selectconvert(char,getdate(),105)--'27-09-2003'selectconvert(char,getdate(),106)--'27Sep2003'selectconvert(char,getdate(),107)--'Sep27,2003'selectc

4、onvert(char,getdate(),108)--'11:16:06'selectconvert(char,getdate(),109)--'Sep27200311:16:28:746AM'selectconvert(char,getdate(),110)--'09-27-2003'selectconvert(char,getdate(),111)--'2003/09/27'selectconvert(char,getdate(),112)--'20030927'selectrtrim(convert(char,getdate(),102))+''+(convert(ch

5、ar,getdate(),108))--'2003.11.1211:03:41'--整数时间selectconvert(int,convert(char(10),getdate(),112))--20031112selectdatepart(hh,getdate())*10000+datepart(mi,getdate())*100+datepart(ss,getdate())--110646--时间格式"YYYY.MM.DDHH:MI:SS"转换为"YYYYMMDDHHMISS"declare@adatetime,@tmpvarchar(20),@tmp1varchar(20

6、)select@a=convert(datetime,'2004.08.0312:12:12')select@tmp=convert(char(10),@a,112)select@tmpselect@tmp1=convert(char(10),datepart(hh,@a)*10000+datepart(mi,@a)*100+datepart(ss,@a))select@tmp1select@tmp=@tmp+@tmp1select@tmp--当月最后一天declare@tmpstrvarchar(10)@mmint,@premmint,@curmmlastdayvarchar

7、(10)beginselect@mm=datepart(month,getdate())--当月select@premm=datepart(month,dateadd(month,-1,getdate()))--上个月if(@mm>=1and@mm<=8)select@tmpstr=convert(char(4),datepart(year,getdate()))+'.0'+convert(char(1),datepart(month,dateadd(month,1,getdate())))

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。