Format | SQL | Example |
---|---|---|
DD/MM/YY | SELECT CONVERT(VARCHAR(8), GETDATE(), 3) | 31/12/13 |
DD/MM/YYYY | SELECT CONVERT(VARCHAR(10), GETDATE(), 103) | 31/12/2013 |
DD/MM/ปี พ.ศ. | CONVERT(VARCHAR(10), DATEADD(yyyy,+543,getdate()), 103) | 31/12/2556 |
YYMMDD | SELECT CONVERT(VARCHAR(6), GETDATE(), 12) | 170428 |
YYYYMMDD | SELECT CONVERT(VARCHAR(8), GETDATE(), 112) | 20170428 |
HH:MM | SELECT substring(CONVERT(VARCHAR, GETDATE(), 121),12,5) | 20:30 |
YYYY-MM-DD | SELECT CONVERT(VARCHAR(10), GETDATE(), 121) | 2013-12-31 |
YYYY-MM-DD HH:MI:SS.MMM(24h) | SELECT CONVERT(VARCHAR(23), GETDATE(), 121) | 2013-12-31 23:59:59.789 |
Tuesday, September 3, 2013
SQL SERVER: Convert DateTime to Formatted Varchar
Subscribe to:
Posts (Atom)