Tuesday, 19 July 2011

New Date and Time functions in "Denali" CTP3

I've been playing around with the CTP3 of Denali and stumbled upon some new functions...
The new functions are :
  •  DATEFROMPARTS(@year, @month, @day)
    • returns a DATE value
  • DATETIMEFROMPARTS(@year, @month, @day, @hour, @minute, @seconds, @milliseconds) 
    • returns a DATETIME value
  •  TIMEFROMPARTS(@hour, @minute, @seconds, @fractions, @precision) 
    • returns a TIME value
    • where @fractions is an integer expression and @precision is an integer literal specifying the precision of the time value to be returned.)
    •   @fractions depend on @precision eg if the precision is 7 then each fraction represents 100 nanoseconds.
Remarks:
  • If the arguments are invalid, then an error is raised
  • If any of the parameters are null, null is returned
Some Examples:

SELECT DATEFROMPARTS(2011, 07, 20) AS 'Todays Date'

SELECT DATETIMEFROMPARTS (2011, 07, 20, 09, 51, 07, 321) AS 'Todays Date and Time'

SELECT TIMEFROMPARTS (09, 51, 07, 321 , 3) AS 'Todays Time'

have fun,
Jurgen