SQL DATETIME2FROMPARTS Function

DATETIME2FROMPARTS creates a datetime2 value with optional precision.

The returned value is based on the specified datepart arguments.

All arguments are required. If any is null, then null is returned.

Example

#

This example returns a datetime2 value from the specified dateparts.

SELECT DATETIME2FROMPARTS(2022, 5, 28, 11, 54, 17, 0, 0) 
    AS Datetime2
Result:  1 record
Datetime2
2022-05-28 11:54:17

Syntax

Syntax of the DATETIME2FROMPARTS function .

DATETIME2FROMPARTS(year, month, day, hour, 
                   minute, seconds, fractions, precision) 

year -- an integer specifying year.

month -- an integer specifying month from 1 to 12.

day -- an integer specifying day of the month.

hour -- an integer specifying the hour.

minute -- an integer specifying the minute.

seconds -- an integer specifying the seconds.

fractions -- an integer specifying the fractional second values.

precision -- an integer specifying the precision of the returned datetime2 value.

Note: DATETIME2FROMPARTS requires 8 arguments. If any of the 8 arguments is invalid an error will be returned. The arguments can be null, except precision. Any null argument will result in a null return value.


You may also like



Guides


vsn 3.1