The above functions are all new time functions in SQL Server 2012.
EOMONTH
Returns the month end date of the incoming time, the return data type is date
SELECT EOMONTH (GETDATE())
Result is
. - on - to
Datefromparts
As in C # or Java declares a DateTime instance by passing in year, month, the number of day is worth a DateTime instance. The same is true here. Get a date by passing in the date. But if you fail to construct a valid time for the incoming parameter, you will get an error.
DECLARE @Year int,@Month int,@Day intSET @Year = -SET @Month = GenevaSET @Day = -SELECTDatefromparts (@Year,@Month,@Day) asMyDate
The result is
289 Level - 1 A Someofvalues not valid.
If it is legal
DECLARE @Year int,@Month int,@Day intSET @Year = -SET @Month = GenevaSET @Day = -SELECTDatefromparts (@Year,@Month,@Day) asMyDate
That's
- - Geneva - -
Timefromparts
Similar to Datefromparts, except that the incoming hour, MINUTE, Second,millisecond, and millisecond exact digits, and then returns a time type. It is important to note that the fifth argument of this function is that the integer variable is not supported, and must be the display constant passed in.
Like what
DECLARE @Hour int,@Minutes int,@Seconds int,@FractionsOfASecond intSET @Hour = theSET @Minutes = atSET @Seconds = -SET @FractionsOfASecond = -SELECTTimefromparts (@Hour,@Minutes,@Seconds,@FractionsOfASecond,3) asMyTime
Results
£ º47.500
What if I pass in a null value?
DECLARE @Hour int,@Minutes int,@Seconds int,@FractionsOfASecond intSET @Hour = theSET @Minutes = atSET @Seconds = -SET @FractionsOfASecond = -SELECTTimefromparts (@Hour,@Minutes,@Seconds,NULL,3) asMyTime
The result is also null
Datetimefromparts
This is a combination of the previous two. The characteristic is that the passed null value is the result becomes null, the illegal value is an error. It is strange that it does not have the exact number of digits of the timefromparts parameter.
DECLARE @Year int,@Month int,@Day int,@Hour intDECLARE @Minutes int,@Seconds int,@MilliSeconds intSET @Year = -SET @Month = -SET @Day = atSET @Hour = -SET @Minutes = -SET @Seconds = theSET @MilliSeconds = 0SELECTDatetimefromparts (@Year,@Month,@Day,@Hour,@Minutes,@Seconds,@MilliSeconds) asMydatetime
Results
- - - - at £ º49.000
Datetimeoffsetfromparts
This is more interesting. Joined the TIMEZONE.
DECLARE @Year int,@Month int,@Day intDECLARE @Hour int,@Minutes int,@Seconds intDECLARE @FractionsOfASecond intDECLARE @HourOffSet int,@MinuteOffSet intSET @Year = -SET @Month = GenevaSET @Day = -SET @Hour = theSET @Minutes = $SET @Seconds = theSET @FractionsOfASecond = -SET @HourOffSet = 7SET @MinuteOffSet = -SELECTDatetimeoffsetfromparts (@Year,@Month,@Day,@Hour,@Minutes,@Seconds,@FractionsOfASecond,@HourOffSet,@MinuteOffSet,3) asMytimezone
SQL Server->> time functions: EOMONTH, Datefromparts, Timefromparts, Datetimefromparts, Datetimeoffsetfromparts