Convertendo datas em texto

DateTime > varchar

Select convert(varchar(30),getdate(),100) > Mar 16 2007 3:06PM
Select convert(varchar(30),getdate(),101) > 03/16/2007
Select convert(varchar(30),getdate(),102) > 2007.03.16
Select convert(varchar(30),getdate(),103) > 16/03/2007
Select convert(varchar(30),getdate(),104) > 16.03.2007
Select convert(varchar(30),getdate(),105) > 16-03-2007
Select convert(varchar(30),getdate(),106) > 16 Mar 2007
Select convert(varchar(30),getdate(),107) > Mar 16, 2007
Select convert(varchar(30),getdate(),108) > 15:06:04
Select convert(varchar(30),getdate(),109) > Mar 16 2007 3:06:04:793PM
Select convert(varchar(30),getdate(),110) > 03-16-2007
Select convert(varchar(30),getdate(),111) > 2007/03/16
Select convert(varchar(30),getdate(),112) > 20070316
Select convert(varchar(30),getdate(),113) > 16 Mar 2007 15:06:04:793
Select convert(varchar(30),getdate(),114) > 15:06:04:793

The list of styles that can be used are:

Style IDÂ Style Type
Â
0 or 100Â mon dd yyyy hh:miAM (or PM)
101Â mm/dd/yy
102Â yy.mm.dd
103Â dd/mm/yy
104Â dd.mm.yy
105Â dd-mm-yy
106Â dd mon yy
107Â Mon dd, yy
108Â hh:mm:ss
9 or 109Â mon dd yyyy hh:mi:ss:mmmAM (or PM)
110Â mm-dd-yy
111Â yy/mm/dd
112Â yymmdd
13 or 113Â dd mon yyyy hh:mm:ss:mmm(24h)
114Â hh:mi:ss:mmm(24h)
20 or 120Â yyyy-mm-dd hh:mi:ss(24h)
21 or 121Â yyyy-mm-dd hh:mi:ss.mmm(24h)
126Â yyyy-mm-dd Thh:mm:ss.mmm(no spaces)
130Â dd mon yyyy hh:mi:ss:mmmAM
131Â dd/mm/yy hh:mi:ss:mmmAM

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *