# Thread: Get Last day of week (Saturday) from any date?

1. Registered User
Join Date
Nov 2003
Posts
3

## Unanswered: Get Last day of week (Saturday) from any date?

Greetings,

Any tips on using datediff to get last day of week( in this case saturday) from a datetime input in SQL?

Thanks for any help!

2. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
Its odd how different people have similar question on this forum at the same time...

declare @datevalue datetime
set @datevalue = '11/12/2003'

blindman

3. Registered User
Join Date
Aug 2003
Location
Stockholm, Sweden
Posts
4

## Re: Get Last day of week (Saturday) from any date?

Originally posted by jackogreen
Greetings,

Any tips on using datediff to get last day of week( in this case saturday) from a datetime input in SQL?

Thanks for any help!
Are you depending on using datediff? And is date of last weekday you want?

4. Window Washer
Join Date
Nov 2002
Location
Jersey
Posts
10,322
Originally posted by blindman
Its odd how different people have similar question on this forum at the same time...

blindman
[blinders on]
[/blinders on]

5. Registered User
Join Date
Oct 2003
Posts
706

## Re: Get Last day of week (Saturday) from any date?

[i]
Any tips on using datediff to get last day of week( in this case saturday) from a datetime input in SQL?
In any language, the solution to this problem is to determine the day-of-the-week of the date entered, then calculate the number of days (0-6) to the following Saturday, then add that number of days to the date entered. Q.E.D.

6. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595
No need to search Brett! This gentleman was looking for the first day of the week:
http://www.dbforums.com/t970121.html

"In any language, the solution to this problem is to determine the day-of-the-week of the date entered, then calculate the number of days (0-6) to the following Saturday, then add that number of days to the date entered. Q.E.D."? Been there, done that.

blindman

7. Registered User
Join Date
Oct 2011
Posts
1

## Calculating day of week in SQL server

To get a deterministic value for the day of week for a given date you could use a combination of datepart and @@firstday. Otherwise your dependent on the settings on the server.

Check out the following site for a solution:
MS SQL: Day of Week | LazerWire.com

The day of week will then be in the range 0 to 6, where 0 is Sunday, 1 is monday, etc

8. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002

i do hope that the original poster hasn't been stuck for these last eight years waiting for a solution

9. Registered User
Join Date
Sep 2001
Location
Chicago, Illinois, USA
Posts
603
Can the operators of this board add some code to prevent users from replying to threads that have not been responded-to in the past month?

If a post lies dormant for more than a month, and the original poster wants to continue the thread, he/she can reference the previous thread in a new thread.

Join Date
Feb 2004
Location
New Zealand
Posts
1,482

11. Registered User
Join Date
Sep 2011
Posts
75

12. World Class Flame Warrior
Join Date
Jun 2003
Location
Ohio
Posts
12,595