Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Created October 1, 2021 15:16
Show Gist options
  • Save shadyrudy/a0d9cac653bedcbd5d5c89d5faf5c4ce to your computer and use it in GitHub Desktop.
Save shadyrudy/a0d9cac653bedcbd5d5c89d5faf5c4ce to your computer and use it in GitHub Desktop.
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