Tag Archives: datetimefromparts in sql server 2012

What is DATETIMEFROMPARTS Function in SQL Server?

DATETIMEFROMPARTS Function was introduced with SQL Server 2012. This function is used to get DateTime value from Year, Month, Day, Hour, Minute, Second and MiliSecond values.
Syntax:
DATETIMEFROMPARTS (Year, Month, Day, Hour, Minute, Second, MiliSecond)
Example:

Declare @Year int = 2015
Declare @Month int = 6
Declare @Day int = 9
Declare @Hour int = 23
Declare @Minute int = 59
Declare @Second int = 59
Declare @MiliSecond int = 0

Select DATETIMEFROMPARTS (@Year, @Month, @Day, @Hour, @Minute, @Second, @MiliSecond)


Result:
June, 09 2015 23:59:59

What is DATEFROMPARTS Function in SQL Server?

DATEFROMPARTS Function was introduced with SQL Server 2012. This function is used to get date value from year, month and day values.
Syntax:
DATEFROMPARTS(Year,Month,Day)
Example:

Declare @Year int = 2015
Declare @Month int = 6
Declare @Day int = 9
Select DATEFROMPARTS(@Year,@Month,@Day)


Result:
2015-06-09