DATETIME2FROMPARTS (TSQL Function)

Returns a datetime created from the specified parts.

Syntax

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

Arguments

year
is an expression of type int.
month
is an expression of type int.
day
is an expression of type int.
hour
is an expression of type int.
minute
is an expression of type int.
seconds
is an expression of type int.
fractions
is the subsecond fractional part. It is of type int. Its precision is given by the precision argument.
precision
precision of the fractions argument. It is of type int, in the range [0, 9].
E.g. 3 means that fractions is specified as milliseconds; 9 is for nanoseconds.

Return Types

Returns datetime.

Examples

PRINT DATETIME2FROMPARTS (2016, 5, 15, 13, 30, 15,         0, 0);
PRINT DATETIME2FROMPARTS (2016, 5, 15, 13, 30, 15,       123, 3);
PRINT DATETIME2FROMPARTS (2016, 5, 15, 13, 30, 15,    123456, 6);
PRINT DATETIME2FROMPARTS (2016, 5, 15, 13, 30, 15, 123456789, 9);

The result is:

2016-05-15 13:30:15
2016-05-15 13:30:15.123000000
2016-05-15 13:30:15.123456000
2016-05-15 13:30:15.123456789
RSQL, a simple alternative to Microsoft SQL Server