Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Useful date formats in SQL Server
* The following are a few useful date formats in SQL Server
* These can be used for various types of output such as status
* or naming files.
select convert(varchar(10), getdate(), 120); /* YYYY-MM-dd */
select convert(varchar(16), getdate(), 120); /* YYYY-MM-dd HH:mm */
select convert(varchar(20), getdate(), 112); /* YYYYMMdd */
select format(getdate(), 'yyyyMMdd_HHmm', 'en-US'); /* YYYYMMdd_HHmm */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment