Issue with Weekdayname function

jonnydexter

Registered User.
Local time
Today, 11:37
Joined
Aug 31, 2012
Messages
21
Hi
i am using the weekdayname function but it has been returning the wrong value when i use the default setting. I set the start day to vbsunday and it worked correctly. i checked the vbUseSystemDayOfWeek and it is returning 0 where i presumed it was going to return 1.
My question is where do i check why this is returning the incorrect day from the documented default ( according to an article on technet)

i have also discovered that "testdate = WeekdayName(vbSunday)" returns "monday" into testdate! presumably this is some system setting soewhere but my computer appears to be set correctly, what am i missing ?

TIA
 
Last edited:
vbUseSystemDayOfWeek is a vb constant. The value that Access is looking for if it is going to use the system default is the value 0 (vbUseSystemDayOfWeek) so the rest of the values are offsets:

vbSunday = 1
vbMonday = 2
vbTuesday = 3
vbWednesday = 4
vbThursday = 5
vbFriday = 6
vbSaturday = 7

It isn't giving you the system value, it is a value for the offset to use in its internal function calculation.
 
This works for me Acc2003

Debug.Print WeekdayName(Weekday(Date), 0, vbUseSystem)

My 2003 help
WeekdayName Function


Description

Returns a string indicating the specified day of the week.

Syntax

WeekdayName(weekday, abbreviate, firstdayofweek)

The WeekdayName function syntax has these parts:

Part Description
weekday Required. The numeric designation for the day of the week. Numeric value of each day depends on setting of the firstdayofweek setting.
abbreviate Optional. Boolean value that indicates if the weekday name is to be abbreviated. If omitted, the default is False, which means that the weekday name is not abbreviated.
firstdayofweek Optional. Numeric value indicating the first day of the week. See Settings section for values.



Settings

The firstdayofweek argument can have the following values:

Constant Value Description
vbUseSystem 0 Use National Language Support (NLS) API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
 
sorry Bob i have posted an edit to the original question and seemed to have cross posted with yourself.

where does vb get the value for the vbUseSystemDayOfWeek ? if the other values are offsets from that, then it must be wrong. as i stated in the edit everything else appears to be ok with the pc ( i have not done extensive checks as of yet though)

thanks again
 
sorry Bob i have posted an edit to the original question and seemed to have cross posted with yourself.

where does vb get the value for the vbUseSystemDayOfWeek ? if the other values are offsets from that, then it must be wrong. as i stated in the edit everything else appears to be ok with the pc ( i have not done extensive checks as of yet though)

thanks again
The code you want was posted by jdraw. You don't put in

WeekdayName(vbSunday)

vbSunday is always 1. It is a CONSTANT. Constants never change.

vbSunday has no association with an actual date.
 
i have put the following lines into my code (to debug) :-

tdim = DateSerial(year(dtdate), month(dtdate) + 1, 1) - DateSerial(year(dtdate), month(dtdate), 1)
testdate = WeekdayName(vbSunday)
fdom = WeekdayName(Weekday(DateSerial(year(Date), month(Date), 1)), , vbUseSystem)

based on todays date (11-09-12)
tdim returns the total days of the month (30)
testdate returns Monday
fdom returns Sunday

but the 1st oif september was (according to my calendar) a saturday.
i believe i have the correct parameters in the dateserial function. Have i missed something here ?
 
Last edited:
i have also tried jdraw's debug code and it also returns tomorrows day not todays.
 
ok - call off the dogs , i think i have found the problem. After trying the things you guys suggested and getting bad results compared to your own, i visited control panel and found that the first day of the week was set for monday. I have no idea why and as far as i know it hasnt affected anything else on my system before this code problem.
Why the hell it is set to monday i dont know, i have never changed it and can only guess that is the default setting MS sets it to on install.
Jdraw's debug code now returns the correct day and i can retest my own code and hopefully move on a little.

thank you for your support
 
To get the number of days in the month just use

Day(DateSerial(Year(dtdate), month(dtdate) + 1, 0))


To get the weekday name of the last day of the month:

WeekdayName(weekDay(DateSerial(Year(dtdate), month(dtdate) + 1, 0)))

You don't need to use the vbUseSystemDayOfTheWeek because it is the default but if you do:

WeekdayName(weekDay(DateSerial(Year(dtdate), month(dtdate) + 1, 0)),,vbUseSystemDayOfWeek)

will work.


And of course
testdate = WeekdayName(vbSunday)

Will return MONDAY. You don't seem to understand. vbSunday is NOT TO BE USED IN THIS CONTEXT. It has NOTHING TO DO WITH THE DATE. It ALWAYS has a value of 1. And if you put

testdate = WeekdayName(1)

it will Always return MONDAY if your regional settings are set to have Monday as the first day of the week.
 
Sorry for the emphasized caps then (as you figured it out before I posted). :D
 

Users who are viewing this thread

Back
Top Bottom