Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MS SQL Date Time Conversion
SELECT CONVERT(VARCHAR, GETDATE(), 0)
-- mon dd yyyy hh:miAM (or PM)
Select Convert(VARCHAR,GetDate(),1)
-- mm/dd/yy
Select Convert(VARCHAR,GetDate(),2)
-- yy/mm/dd
Select Convert(VARCHAR,GetDate(),3)
-- dd/mm/yy
Select Convert(VARCHAR,GetDate(),4)
-- dd.mm.yy
Select Convert(VARCHAR,GetDate(),5)
-- dd-mm-yy
Select Convert(VARCHAR,GetDate(),6)
-- dd mon yy
Select Convert(VARCHAR,GetDate(),7)
-- mon dd, yy
Select Convert(VARCHAR,GetDate(),8)
-- hh:mi:ss
Select Convert(VARCHAR,GetDate(),9)
-- mon dd yyyy hh:mi:ss:mmmAM (or PM)
Select Convert(VARCHAR,GetDate(),10)
-- mm-dd-yy
Select Convert(VARCHAR,GetDate(),11)
-- yy/mm/dd
Select Convert(VARCHAR,GetDate(),12)
-- yymmdd
Select Convert(VARCHAR,GetDate(),13)
-- dd mon yyyy hh:mi:ss:mmm(24h) (European Std.)
Select Convert(VARCHAR,GetDate(),14)
-- hh:mi:ss:mmm(24h)
Select Convert(VARCHAR,GetDate(),20)
-- yyyy-mm-dd hh:mi:ss(24h) (ODBC canonical)
Select Convert(VARCHAR,GetDate(),21)
-- yyyy-mm-dd hh:mi:ss.mmm(24h)
Select Convert(VARCHAR,GetDate(),22)
-- mm/dd/yy hh:mi:ss A/PM
Select Convert(VARCHAR,GetDate(),23)
-- yyyy-mm-dd
Select Convert(VARCHAR,GetDate(),24)
-- hh:mm:ss
Select Convert(VARCHAR,GetDate(),25)
-- yyyy-mm-dd hh:mi:ss.mmm(24h)
SELECT CONVERT(VARCHAR(20),GETDATE(), 100)
-- mm dd yyyy hh:mmA/PM
SELECT CONVERT(VARCHAR(10), GETDATE(), 101)
-- mm/dd/yyyy (US Std.)
SELECT CONVERT(VARCHAR(10), GETDATE(), 102)
-- yyyy.mm.dd (ANSI Std.)
SELECT CONVERT(VARCHAR(10), GETDATE(), 103)
-- dd/mm/yyyy (British/French Std.)
SELECT CONVERT(VARCHAR(10), GETDATE(), 104)
-- dd.mm.yyyy (German Std.)
SELECT CONVERT(VARCHAR(10), GETDATE(), 105)
-- dd-mm-yyyy
SELECT CONVERT(VARCHAR(11), GETDATE(), 106)
-- dd mon yyyy
SELECT CONVERT(VARCHAR(12), GETDATE(), 107)
-- mon dd, yyyy
SELECT CONVERT(VARCHAR(8), GETDATE(), 108)
-- hh:mi:ss
SELECT CONVERT(VARCHAR(26), GETDATE(), 109)
-- mon dd yyyy hh:mi:ss:mmmAM (or PM)
SELECT CONVERT(VARCHAR(10), GETDATE(), 110)
-- mm-dd-yyyy (US standard)
SELECT CONVERT(VARCHAR(10), GETDATE(), 111)
-- yyyy/mm/dd (Japan Std.)
SELECT CONVERT(VARCHAR(8), GETDATE(), 112)
-- yyyymmdd (ISO Std.)
SELECT CONVERT(VARCHAR(24), GETDATE(), 113)
-- dd mon yyyy hh:mi:ss:mmm(24h) (European Std.)
SELECT CONVERT(VARCHAR(12), GETDATE(), 114)
-- hh:mi:ss:mmm(24h)
SELECT CONVERT(VARCHAR(19), GETDATE(), 120)
-- yyyy-mm-dd hh:mi:ss(24h) (ODBC canonical)
SELECT CONVERT(VARCHAR(23), GETDATE(), 121)
-- yyyy-mm-dd hh:mi:ss.mmm(24h)
SELECT CONVERT(VARCHAR(23), GETDATE(), 126)
-- yyyy-mm-ddThh:mi:ss.mmm (no spaces)
SELECT CONVERT(VARCHAR(26), GETDATE(), 130)
-- dd mon yyyy hh:mi:ss:mmmAM (Hijri)
SELECT CONVERT(VARCHAR(25), GETDATE(), 131)
-- dd/mm/yyyy hh:mi:ss:mmmAM (Hijra)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.