Introduction
In this post i will explain about different commonly used Date-Time format's in SQL server with example. You can learn how to format date and time by many ways in SQL server for your different requirements.
Date Formats In SQL
DateTime Formats In SQL
Date Formats In SQL
Date Format
|
Expression
|
Output
|
MM/DD/YY
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 1) |
03/19/17
|
MM/DD/YYYY
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 101) |
03/19/2017
|
MM-DD-YY
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 10) |
03-19-17
|
MM-DD-YYYY
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 110) |
03-19-2017
|
DD/MM/YY
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 3) |
19/03/17
|
DD/MM/YYYY
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) |
19/03/2017
|
DD.MM/YY
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 4) |
19.03.17
|
DD.MM/YYYY
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 104) |
19.03.2017
|
DD-MM-YY
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 5) |
19-03-17
|
DD-MM-YYYY
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 105) |
19-03-2017
|
YY.MM.DD
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 2) |
17.03.19
|
YYYY.MM.DD
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 102) |
2017.03.19
|
YY/MM/DD
|
SELECT CONVERT(VARCHAR(8), GETDATE(), 11) |
17/03/19
|
YYYY/MM/DD
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 111) |
2017/03/19
|
DD
Mon YY
|
SELECT CONVERT(VARCHAR(9), GETDATE(), 6) |
19
Mar 17
|
DD
Mon YYYY
|
SELECT CONVERT(VARCHAR(11), GETDATE(), 106) |
19
Mar 2017
|
Mon
DD, YY
|
SELECT CONVERT(VARCHAR(10), GETDATE(), 7) |
Mar
19, 17
|
Mon
DD, YYYY
|
SELECT CONVERT(VARCHAR(12), GETDATE(), 107) |
Mar
19, 2017
|
DateTime Formats In SQL
SELECT CONVERT(VARCHAR(8), GETDATE(), 108)
Output- 23:14:24 (HH:MI:SS)
SELECT CONVERT(VARCHAR(26), GETDATE(), 109)
Output- Mar 19 2017 11:14:24:107PM
SELECT CONVERT(VARCHAR(24), GETDATE(), 113)
Output - 19 Mar 2017 23:18:02:463
SELECT CONVERT(VARCHAR(12), GETDATE(), 114)
Output- 23:22:15:270
SELECT CONVERT(VARCHAR(19), GETDATE(), 120)
Output- 2017-03-19 23:22:15
SELECT CONVERT(VARCHAR(23), GETDATE(), 121)
Output- 2017-03-19 23:22:15.270
SELECT CONVERT(VARCHAR(23), GETDATE(), 126)
Output- 2017-03-19T23:22:15.270
|
0 comments:
Post a Comment