Create Date and DateTime using values in SQL Server

Year, Month, Day are columns in MyTable table

Create Date from numbers

To create Date: DATEFROMPARTS ( year, month, day )

Select
datetimefromparts([Year], [Month], [Day]) as Submission_Date
From MyTable

Output: 2019-01-02

Create Date and Time from numbers

To create Date and Time: DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )

Select
datetimefromparts([Year], [Month], [Day], 00,00,00,0) as Submission_Date
From MyTable

Output: 2022-06-20 00:00:00.000

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s