Click here to Skip to main content
12,623,724 members (33,831 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

9.5K views
5 bookmarked
Posted

Find all SQL Server DateTime Formats

, 25 Mar 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
When using DateTime with SQL Server, I often forget what the parameters are that allow formatting DateTime in specific ways. When that happens, I fire up this code fragment in SQL Server Management Studio and it neatly lists out every possible parameter with example output.declare @Loop...
When using DateTime with SQL Server, I often forget what the parameters are that allow formatting DateTime in specific ways. When that happens, I fire up this code fragment in SQL Server Management Studio and it neatly lists out every possible parameter with example output.

declare @Loop int
set @Loop = -1
 
declare @table table
(
    [Date] nvarchar(50) not null,
    [Param] int not null
)
 
while @Loop <= 150
begin
    set @Loop = @Loop + 1
 
    begin try
        insert into @table
        select convert(nvarchar, getdate(), @Loop), @Loop
    end try
 
    begin catch
        continue
    end catch
end
 
select * from @table

Sample output:

Date                                               Param
-------------------------------------------------- -----------
Mar 24 2010  8:22AM                                0
03/24/10                                           1
10.03.24                                           2
24/03/10                                           3
24.03.10                                           4
24-03-10                                           5
24 Mar 10                                          6
Mar 24, 10                                         7

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

R. Giskard Reventlov
Founder
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralSimply press F1 and write date formats.. Pin
ran.sharabi23-Mar-10 23:50
memberran.sharabi23-Mar-10 23:50 
GeneralRe: Simply press F1 and write date formats.. Pin
digital man24-Mar-10 1:49
memberdigital man24-Mar-10 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 26 Mar 2010
Article Copyright 2010 by R. Giskard Reventlov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid