DATEFROMPARTS

Aaron Bertrand looks at the DATEFROMPARTS function in SQL Server 2012 and later:

The point of these functions is to make it easier to construct a date, or datetime, or datetime2 variable, when you know the individual parts. DATEFROMPARTS() takes three arguments: year, month, and day, and returns adate value. So, for example, SELECT DATEFROMPARTS(2016,7,6); would yield the date 2016-07-06.

Read on for a comparison of this function against about a dozen other methods of building dates from components.

Related Posts

Getting The Current Date And Time In SQL Server

Randolph West shows a few functions which can retrieve current date and time information: What do we mean by local date and time? As discussed previously, SQL Server is not time zone aware, nor does it have to be. This is because the operating system that SQL Server runs on can have multiple custom regional settings […]

Read More

DateTime Arithmetic

Claudio Silva points out a difference between the DATETIME and DATETIME2 data types: I’m currently working on a SQL code migration from Firebird to SQL Server and I hit an error that I haven’t seen for some time. The error message is the following: Msg 206, Level 16, State 2, Line 4 Operand type clash: datetime2 is […]

Read More

Categories

July 2016
MTWTFSS
« Jun Aug »
 123
45678910
11121314151617
18192021222324
25262728293031