Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Date Part Function in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 54
    Comment on it

    While extracting specific portion from Date or from Date Time  we can use Date Part functions for doing that

    -- Declare Variable
    
    Declare @UserID;
    
    --Extracting Day Month and Year
    
    SELECT DATEPART(yyyy,UserCreated) AS UserYear,
    DATEPART(mm,MonthofCreation) AS UserMonth,
    DATEPART(dd,DayofCreation) AS UserDay
    FROM Users
    WHERE UserId=@UserID
    Output:
    
    10,10,2014

    In this example the user day of creation its month of creation and its year of creation is extracted from date

    Code             Meaning
    
    year, yyyy, yy 	 Year interval
    quarter, qq, q 	 Quarter interval
    month, mm, m 	 Month interval
    dayofyear 	 Day of year interval
    day, dy, y 	 Day interval
    week, dw, w 	 Week interval
    weekday, ww, wk  Weekday interval
    hour, hh 	 Hour interval
    minute, mi, n 	 Minute interval
    second, ss, s 	 Second interval
    millisecond, ms  Millisecond interval

     

    SQL Server

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: