HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

Get all CONVERT(datetime) styles (formats)

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
allconvertstylesgetformatsdatetime

Problem

I know this is kinda stupid to ask but is there a Transact-SQL function or anything that returns all CONVERT(datetime) styles (formats)? Something like fnDateFormats will return all date formats:

Output:

Dateformat | SQL code
MM/DD/YYYY | 101

and so on.

Solution

There is no such built-in function – or system table, or view – that would give you a list of all styles (formats). Otherwise people would not have been creating custom-made style lists (like this one, for instance) – as a way of a reminder, I guess, because the same information can be found in the online documentation, even if slightly differently arranged.

Go ahead and create one for yourself. New styles are sometimes introduced with new major releases, but those do not happen too often, so maintaining such a list should not be much of a burden.

Another thing is whether you really need to have such a table. Unless you are still using a pre-2012 version, you can format your datetime values arbitrarily with the FORMAT() function.

Context

StackExchange Database Administrators Q#183693, answer score: 11

Revisions (0)

No revisions yet.