Thursday, August 4, 2011

SQL Server Denali: Get Date/Time from Parts


SQL Server Denali has made developers life quite easy by introducing new useful functions. We have already discussed EOMONTH() in an early post.
DATEFROMPARTS() is a new function introduced in SQL Server Denali, which will help us to avoid lengthy code to get date from year, month and day inputs. DATEFROMPARTS() takes three input parameters YEAR, MONTH and DAY and returns value in DATE format.
DATEFROMPARTS ( year, month, day )









DATEFROMPARTS() is not only function to get DATETIME values from parts but 5 other functions are also introduced.
  1. TIMEFROMPARTS () which returns output in TIME format.
TIMEFROMPARTS ( hour, minute, seconds, fractions, precision )
  1. SMALLDATETIMEFROMPARTS() which returns output in SMALLDATETIME2 format.
SMALLDATETIMEFROMPARTS ( year, month, day, hour, minute )
  1. DATETIMEFROMPARTS() which returns output in DATETIME format.
DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )
  1. DATETIME2FROMPARTS() which returns output in DATETIME2 format.
DATETIME2FROMPARTS ( year, month, day, hour, minute, seconds, fractions, precision )
  1. DATETIMEOFFSETFROMPARTS() which returns output in datetimeoffset format.
DATETIMEOFFSETFROMPARTS ( year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision )



------------------------------------------------------------------------------------
Read More about SQL Server 2012 (Code Name: Denali

·         Introducing New Edition "Business Intelligence"

·         Changing Backup Files Default Path is More Easy Now

·         New Backup/Restore Options

·         CTP 3 Product Guide Released

·         TRY_CONVERT(), a Good Addition

·         Table Partition Limit Enhancement

·         Format(), a Most Wanted Function

·         New Function to Get Last Date of Month

·         IIF Logical Function

·         A New More Flexible Create Index Dialog box



No comments:

Post a Comment

All suggestions are welcome