Well,the function states that build a date given the various parts like year, month and day. We have already seen this function in dotnet. Out of the various overloaded constructor of DateTime struct, we have
public DateTime(int year, int month, int day);
So if we write
Console.WriteLine(new DateTime(2011, 7, 23));
The output will be: 7/23/2011 12:00:00 AM
Now we have the same opportunity to do from Sql Server with the help of DateFromParts.
Purpose: Returns a date given its parts like year, month, day.
Syntax: DateFromParts(year,month,day)
Where,
Year => the year value
Month => the month value
Day => Day value.
Example 1: Simple example
Select DateFromParts(2011,7,23) [Result]
/*
Result
------
2011-07-23
*/
Example 2: Specifying all nulls
Select DateFromParts(null,null,null) [Result]
/*
Result
------
Null
*/
Example 3: Omitting mandatory fields will raise exception
Select DateFromParts(2011,23) [Result]
Msg 174, Level 15, State1, Line1
The datefromparts function requires 3 argument(s)
Example 4: Inserting value 2 for all the fields
Select DateFromParts(2,2,2) [Result]
/*
Result
------
0002-02-02
*/
Hope this helps