putting variables into the weekday() function

W

warnett

hey there all.
Been using access for my project at school and I need the system to work out
the day of the week for me, given a date stored in a variable. Found
something with access though:

WeekDay("07/11/2005",2) returns 1 (monday which is correct)

but using a variable of either data type date or string with this value
stored returns an incorrect value. calling this variable datedate just for
this purpose

WeekDay(datedate,2) returns 6 (saturday which is wrong).

I have tried both a string and a date for the data type of the variable but
it still wishes to produce the wrong answer. I believe it is to do with
quotation marks around the date. Any ideas.

Thanks Jason
 
A

Allen Browne

WeekDay() expects 2 arguments:
- a date value
- an integer between 1 and 7, where 1 = Sunday.

Therefore the correct way to ask for the weekday of July 11th assuming
Monday is the first day of the week would be:
WeekDay(#07/11/2005#, 2)
and that returns 1 because July 11 was a Monday this year.

It is unclear what "datedate" was in your expression, so it is difficult to
say why Saturday is wrong. Where I live it is Tuesday, so
WeekDay(Date, 2)
returns 2 today (i.e. Tue is the 2nd day of the week, if Monday is the first
day of the week.)

Note that the string version of a date is interpreted differently that a
literal date (delimited by #). It depends on the date format you set it
Windows Control Panel, under Regional Options. More info on that:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top