I am using SQL Server 2014 and I have a table (t1) which has the following 3 columns:
DAY MONTH YEAR
2 11 2021
1 10 2021
12 10 2021
22 09 2021
All the 3 columns have a float datatype.
What would be the t-sql code to build a date from these 3 columns in the following format (YYYY-MM-DD):
CREATEDDATE
2021-11-02
2021-10-01
2021-10-12
2021-09-22
I have tried looking around for other questions similar to mine but I could not find a solution.
Any help would be appreciated.
The DATEFROMPARTS()
function is an option ( ... returns a date value that maps to the specified year, month, and day values ):
SELECT DATEFROMPARTS([YEAR], [MONTH], [DAY])
FROM (VALUES
(2, 11, 2021),
(1, 10, 2021),
(12, 10, 2021),
(22, 09, 2021)
) t ([DAY], [MONTH], [YEAR])
Or with the actual table:
SELECT DATEFROMPARTS([YEAR], [MONTH], [DAY])
FROM t1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.