Finding the past Sunday

# Thread: Finding the past Sunday

1. Senior Member
Join Date
Dec 1969
Posts
653

## Finding the past Sunday

Hi...how can get the date value of the nearest past Sunday. For example if today was 1/19/2001...the nearest past sunday date value would have 1/14/2001 similarly if today was 1/14/2001 then the nearest past Sunday would have the value 1/14/2001...is it possible to do in ASP???<BR><BR>Please help!

2. Senior Member
Join Date
Dec 1969
Posts
915

## I had a post yesterday that...

did almost exactly this. I think with a tweak or two, it would give you what you are looking for.<BR><BR>Just do a search (upper right) and search for posts by me.<BR><BR>HTH<BR><BR>Jerry

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## *THE* quickest and easiest way:

&#060;%<BR>pastSunday = Date - Weekday(Date) + 1<BR>%&#062;<BR><BR>How it works: <BR><BR>Date -- gives today&#039;s date<BR>Weekday(Date) -- gives 1 for Sunday, 2 for Monday, etc.<BR><BR>So:<BR><BR>If today *is* Sunday, then Weekday(Date) is 1, and Date-1+1 give...today!<BR>If today is Monday, then Weekday(Date) is 2, and Date-2+1 gives...yesterday...which is Sunday!<BR>etc.<BR>If today is Saturday, then Weekday(Date) is 7, and Date-7+1 gives a date 6 days ago...which is Sunday!<BR><BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Might be a bug in VBS doing that...

Almost forgot: We were doing<BR>&#060;%<BR>value = Date - Weekday(Date,2) + 1<BR>%&#062;<BR>and VBS was giving a syntax error. A *clear* error on VBS&#039;s part!<BR><BR>We changed it to<BR>&#060;%<BR>value = Date + 1 - Weekday(Date,2) <BR>%&#062;<BR>and it worked perfectly. I *suspect* that the culprit was the unusual usage of Weekday [that is, with two arguments], but just in case...<BR><BR>If the code I showed in prior msg doesn&#039;t work, then try this:<BR><BR>&#060;%<BR>lastSunday = Date + 1 - Weekday(Date)<BR>%&#062;<BR><BR>[ Give Kristin Hedge credit for finding this wonderfully short way of doing this! Incidentally, the Weekday(Date,2) trick finds the most recent MONDAY, instead of Sunday. Just adjust the number which is second arg to Weekday to get the most recent day of the week of your choice! ]<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•