Created
October 1, 2021 15:16
-
-
Save shadyrudy/a0d9cac653bedcbd5d5c89d5faf5c4ce to your computer and use it in GitHub Desktop.
Useful date formats in SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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