SQL Server Denali: Get Date/Time from Parts


SQL Server Denali has madedevelopers life quite easy by introducing new useful functions. We have alreadydiscussed EOMONTH() in anearly 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 dayinputs. DATEFROMPARTS() takes three input parameters YEAR, MONTH and DAYand returns value in DATE format.
DATEFROMPARTS ( year, month, day )

DATEFROMPARTS() is not onlyfunction to get DATETIME values from parts but 5 other functions are alsointroduced.

  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 )
    Advertisements

    Posted on August 4, 2011, in SQL Server Denali, T-SQL Cursors. Bookmark the permalink. Leave a comment.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: