Getdate() Formatting

I get the occasional question from our Oracle DBAs on how do you do this in MSSQL.  Usually I have little to no idea, so I do what all new DBAs do:  Look it up.  Well, this situation came up today on how can I write a procedure that will query the table and give me all the enteries for today.  The column the date is stored in is varchar in this format 11/14/2008.  I found the answer is select convert(varchar,getdate(),101)  So I thought I’d add the sytle ID numbers for future reference.

Style ID

Style Type

0 or 100 mon dd yyyy hh:miAM (or PM)
101 mm/dd/yyyy
102 yyyy.mm.dd
103 dd/mm/yyyy
104 dd.mm.yyyy
105 dd-mm-yyyy
106 dd mon yyyy
107 Mon dd, yyyy
108 hh:mm:ss
9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM)
110 mm-dd-yyyy
111 yyyy/mm/dd
112 yyyymmdd
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/yyyy hh:mi:ss:mmmAM

Tags: ,

Leave a Reply

Anti-Spam Protection by WP-SpamFree