View Full Version : Need help with a date function.


odin1701
08-02-2007, 07:47 AM
Here is what I'm trying to do.

I need a function which takes the current day and finds the date of that weeks Sunday.

Then I need to take that date (of the Sunday) and subtract 13 weeks from it.

This is for the criteria in a query so that the only data displayed will be the previous 13 weeks worth.

Not quite sure how to go about this. TIA for the help.

Rabbie
08-02-2007, 07:55 AM
try this

date()-weekday(date(),1)-91

Explanation

Date() is todays date.

Weekday(date(),1) returns a number between 0 and 6 depending on which day it is so now we have the most recent sunday date.

13 weeks is 91 days so we move the date back as desired.

odin1701
08-02-2007, 09:30 AM
I got it figured finally. This is what I used:

Between DateAdd("ww",-13,DateAdd("d",1-Weekday(Date(),1),Date())) And DateAdd("d",1-Weekday(Date(),1),Date())

Brianwarnock
08-02-2007, 10:21 AM
don't know why Odin didn't follow up Rabbie's neat solution , even if it did have a slight error
Rabbie had
date()-weekday(date(),1)-91

but if Sunday is day1 the it should be
date()-weekday(date(),1)+1-91

or date()-weekday(date(),1)-90

or date()-weekday(date(),2)-91 ie make Monday day1

Brian