Efe
Efe

Reputation:

First day Of this week and last week

I am currently getting first day Of this week and last week values with vbscript function in 2/12/2009 format. I was wondering if it was possible with SQL query.

Upvotes: 5

Views: 34544

Answers (3)

mohitkumarmodi
mohitkumarmodi

Reputation: 1

Get the first day of current week.
for extra information use this link.

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_dayofweek

select date(curdate()-DAYOFWEEK(curdate()-1)) as dat;

Upvotes: 0

George
George

Reputation: 41

Ben's answer gives the wrong answer if today is Sunday. Regardless of whether the first day of the week is Sunday or Monday, the current date should be included in the current week. When I run his code for 3/24/2013, it gives me a ThisWeekStart of 3/25/2013. I used the following code instead: SELECT DATEADD(DAY, 1 - DATEPART(DW, '3/24/2013'), '3/24/2013')

Upvotes: 4

Ben Griswold
Ben Griswold

Reputation: 18341

These statements should do what you want in TSQL. Note, the statements are based on the current date. You can replace getdate() for whatever date you wish:

Select dateadd(wk, datediff(wk, 0, getdate()) - 1, 0) as LastWeekStart
Select dateadd(wk, datediff(wk, 0, getdate()), 0) as ThisWeekStart
Select dateadd(wk, datediff(wk, 0, getdate()) + 1, 0) as NextWeekStart

There are lots of other date routines here.

Upvotes: 12

Related Questions