资源描述:
《SQL的datetime类型数据转换为字符串格式大全.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、SQL的datetime类型数据转换为字符串格式大全2007—10—1011:11:432007/10/10SELECTconvert(char(20),getdate(),120)asTIME_1,convert(char(20),getdate(),111)asTIME_2TIME_1TIME_22007—10-1011:20:0920071010112009SELECTconvert(char(20),getdate(),120)asTIME_1,replace(replace(replace(CONVERT(varcha
2、r,getdate(),120),’-’,''),’',''),':’,'')asTIME_2SQL的datetime类型数据转换为字符串格式大全SELECTCONVERT(varchar,getdate()),CONVERT(varchar,getdate(),0)as’0'——042720101:38PM/042720101:38PM,CONVERT(varchar,getdate(),1)as’1'-—042720101:40PM/04/27/10,CONVERT(varchar,getdate(),2)as’2’-—04
3、2720101:42PM/10。04.27,CONVERT(varchar,getdate(),3)as’3’-—042720101:43PM/27/04/10,CONVERT(varchar,getdate(),4)as'4’-—042720101:43PM/27。04。10,CONVERT(varchar,getdate(),5)as’5'——042720101:43PM/27-04—10,CONVERT(varchar,getdate(),6)as'6'--042720101:44PM/270410,CONVERT(var
4、char,getdate(),7)as’7'——042720101:44PM/0427,10,CONVERT(varchar,getdate(),8)as'8'--042720101:44PM/13:44:41,CONVERT(varchar,getdate(),9)as’9’--042720101:44PM/042720101:44:56:467PM,CONVERT(varchar,getdate(),10)as'10'--042720101:45PM/04—27-10,CONVERT(varchar,getdate(),11
5、)as’11'—-042720101:45PM/10/04/27,CONVERT(varchar,getdate(),12)as’12’--042720101:46PM/100427,CONVERT(varchar,getdate(),13)as'13’--042720101:46PM/2704201013:46:13:903,CONVERT(varchar,getdate(),14)as’14’-—042720101:46PM/13:46:37:747,CONVERT(varchar,getdate(),100)as'100’
6、—-042720101:46PM/042720101:46PM,CONVERT(varchar,getdate(),105)as'105’--042720101:48PM/27-04-2010,CONVERT(varchar,getdate(),110)as’110'—-042720101:49PM/04—27—2010,CONVERT(varchar,getdate(),111)as’111’——042720101:49PM/2010/04/27,CONVERT(varchar,getdate(),112)as’112'-—0
7、42720101:50PM/20100427,CONVERT(varchar,getdate(),114)as’114’——042720101:50PM/13:50:37:497将字符串20100426103059转换为datetime类型2010—04-2610:30:59declare@vvarchar(30)set@v=’20100426103059'set@v=left(@v,4)+'—’+substring(@v,5,2)+’-’+substring(@v,7,2)+’’+substring(@v,9,2)+':'+s
8、ubstring(@v,11,2)+':’+right(@v,2)selectcast(@vasdatetime)declare@varvarchar(30)set@var=’20100426103059’selectcast(left(convert(date