Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Server : Useful datetime functions to find specific dates

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 588
    Comment on it

    Following are some useful SQL Server Date functions to find specific dates.

    1) Today

    1. SELECT GETDATE() 'Today'

    2) Yesterday

    1. SELECT DATEADD(d,-1,GETDATE()) 'Yesterday'

    3) First Day of Current Week

    1. SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) 'First_Day_Current_Week'

    4) Last Day of Current Week

    1. SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6) 'Last_Day_Current_Week'

    5) First Day of Last Week

    1. SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) 'First_Day_Last_Week'

    6) Last Day of Last Week

    1. SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6) 'Last_Day_Last_Week'

    7) First Day of Current Month

    1. SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) 'First_Day_Current_Month'

    8) Last Day of Current Month

    1. SELECT DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0))) 'Last_Day_Current_Month'

    9) First Day of Last Month

    1. SELECT DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)) 'First_Day_Last_Month'

    10) Last Day of Last Month

    1. SELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))) 'Last_Day_Last_Month'

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: