SQL DATETIMEFROMPARTS

SQL Server DATETIMEFROMPARTS function is one of the Date and Time Functions, which will return a DateTime value from the user’s specified parts. The basic syntax of the SQL DATETIMEFROMPARTS Function is as follows:

DATETIMEFROMPARTS (year, month, day, hour, minute, seconds, milliseconds)

As you can see from the above syntax, it accepts seven arguments to build date and time. This method returns the DateTime data type value as output.

SQL DATETIMEFROMPARTS Function Example

In this Date and Time example, we will show you the use of SQL Server Date time from parts function.

SELECT DATETIMEFROMPARTS ( 2017, 12, 19, 10, 09, 18, 503 ) AS Result

SELECT DATETIMEFROMPARTS ( 2017, 12, 19, 10, 09, 18, 0 ) AS Result

SELECT DATETIMEFROMPARTS ( 2017, 12, 19, 00, 00, 18, 503 ) AS Result

-- Let me try the NULL values
SELECT DATETIMEFROMPARTS ( NULL, 12, 19, 00, 00, 18, 503 ) AS Result

SELECT DATETIMEFROMPARTS ( 2017, 12, 19, NULL, 00, 18, 503 ) AS Result
SQL DATETIMEFROMPARTS Function 1
Categories SQL