what I am trying to achieve is to get weekday from date
First off, your code is going to retrieve the week day name of
the day before your date, not the week day name of the
actual date. Is this what you want?
FirstDayOfWeek is optional and defaults to 1, which means Sunday; that's not the issue here.
The reason this identical syntax fails (I think) is this:
WeekdayName(Weekday(#17/02/2007#)-1 )
is retrieving the WeekDayName of 17/02/2007 (Saturday) and then, with the
-1, is yielding the previous WeekDayName, which is Friday. And this works fine!
The problem when you change the date to 18/02/2007 is that 18/02/2007 is a Sunday. Then, with the
-1, you're once again trying to get the WeekDayName that comes before Sunday, and in Access' mind, when the
FirstDayOfWeek is set to Sunday
, there is no day of the week before Sunday! And so the code fails if the day entered is a Sunday.
The way around this is to subtract your
1 from the date first,
then evaluate the WeekDayName from this date. You do this by including a second set of parentheses .
Instead of
WeekdayName(Weekday(#18/02/2007#)-1)
use
WeekdayName(Weekday(
(#18/02/2007#)-1
) )
Linq
;0)>