Dofactory.com
Dofactory.com
Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

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



Last updated on Dec 21, 2023

Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.