STRING 2 DATE
SourceFormat | Example |
---|---|
yyyy.mm.dd | SELECT convert(datetime, ‘2021.03.30’, 102) |
dd.mm.yyyy | SELECT convert(datetime, ‘30.03.2021’, 104) |
dd/mm/yyyy | SELECT convert(datetime, ’30/03/2021′, 103) |
yyyy-mm-dd | SELECT convert(datetime, ‘2016-10-28’, 126) |
further Information:
- CAST and CONVERT (Transact-SQL)
- Edgewood Solutions – Date and Time Conversions Using SQL Server
- Rajendra Gupta – SQL Convert Date functions and formats
DATE 2 STRING
TargetFormat | Example |
---|---|
dd.mm.yyyy | |
dd/mm/yyyy | |
yyyy-mm-dd | |
yyyymmdd | Select Convert(CHAR(8),<date>,112) Select cast(Convert(CHAR(8),<date>,112) as int) |
A very important usecase – especially for creating Cubes – is converting a date to yyyymmdd (int)
further informaiton:
- https://www.mssqltips.com/sqlservertip/6452/sql-convert-date-to-yyyymmdd/