How to get first day of the week and last day of the week in sql server 2008?

How to get the first day of the week and last day of the week when we input any one day of a week?

For example if we enter a date then the first(Monday) and last (Friday) day should be displayed.
that is if we enter 24-jan-2014 then 20-jan-2014 and 24-jan-2014 should be displayed.

  • Executing SQL Server Agent Job from a stored procedure and returning job result
  • sqlSave and sqlDrop in R
  • In SQL Server 2008 R2 script data missing on Script Wizard
  • Multiple value parameter only showing first value
  • Aggregate SQL Rows into single column
  • How to determine which columns are shared between two tables?
  • Regards

  • How to sum count value in SQL Server?
  • Conditional statement in sql server 2k5
  • SQL Server 2008 error - cannot allocate space for object
  • how to check difference in time
  • To subtract a previous row value in SQL Server 2012
  • Update table inner join with 3rd table
  • 3 Solutions collect form web for “How to get first day of the week and last day of the week in sql server 2008?”

    Here’s how you can do it:

    DECLARE @yourdate date = getdate()
    Select dateadd(ww, datediff(ww, 0, @yourdate), 0)
    Select dateadd(ww, datediff(ww, 0, @yourdate), 4)
    

    You set @yourdate to the date you want. The first SELECT will give you the first day and the second SELECT will give you the last date

    Try this

    SELECT DATEADD(wk, DATEDIFF(wk, 6, '5/13/2005'), 6)
    SELECT DATEADD(wk, DATEDIFF(wk, 5, '5/13/2005'), 5)
    

    (Or)

    Declare @Date datetime
    Det @Date = '2012-04-12'
    Delect @Date - DATEPART(dw, @Date) + 1 FirstDateOfWeek,
           @Date + (7 - DATEPART(dw, @Date)) LastDateOfWeek
    

    This solves it and also wraps around year ends:

    SELECT DATEADD(wk, DATEDIFF(d, 0, ’01 January 2017′) / 7, 0)

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.