SQL datetime format

The following conversion options are available for sql datetime format :

select convert(char, getdate(), 100) — mon dd yyyy hh:mmAM (or PM)

— Oct  2 2008 11:01AM

select convert(char, getdate(), 101) — mm/dd/yyyy

— 10/02/2008

select convert(char, getdate(), 102) — yyyy.mm.dd

— 2008.10.02

select convert(char, getdate(), 103) — dd/mm/yyyy

select convert(char, getdate(), 104) — dd.mm.yyyy

select convert(char, getdate(), 105) — dd-mm-yyyy

select convert(char, getdate(), 106) — dd mon yyyy

select convert(char, getdate(), 107) — mon dd, yyyy

select convert(char, getdate(), 108) — hh:mm:ss

select convert(char, getdate(), 109) — mon dd yyyy hh:mm:ss:mmmAM (or PM)

— Oct  2 2008 11:02:44:013AM

select convert(char, getdate(), 110) — mm-dd-yyyy

select convert(char, getdate(), 111) — yyyy/mm/dd

select convert(char, getdate(), 112) — yyyymmdd

select convert(char, getdate(), 113) — dd mon yyyy hh:mm:ss:mmm

— 02 Oct 2008 11:02:07:577

select convert(char, getdate(), 114) — hh:mm:ss:mmm(24h)

select convert(char, getdate(), 120) — yyyy-mm-dd hh:mm:ss(24h)

select convert(char, getdate(), 121) — yyyy-mm-dd hh:mm:ss.mmm

select convert(char, getdate(), 126) — yyyy-mm-ddThh:mm:ss.mmm

— 2008-10-02T10:52:47.513

Leave a Reply