Weekday() result differs from one computer to another ???

B

bobm

Hello,

Don't why I get different a result from one computer to another using the
Weekday and Weekday name functions. I am specifying Sunday as weekday 1 not
using the default and still get different results.

The code I am using is...

WeekdayName(Weekday(StartDate, vbSunday), vbSunday)

On one computer which is correct I get...

1 Sun
2 Mon
3 Tue... etc

On the other I get...
1 Mon
2 Tue
3 Wed... etc

The worksheet function works correctly on both but not VBA. Any help
appreciated.

bobm
 
K

K Dales

The worksheet function has 2 arguments, the VBA function has 3:
WeekdayName(weekday, abbreviate, firstdayofweek)
So where you are using vbSunday it is interpreting it as the 'abbreviate'
parameter = 1, True; and because you don't specify the 'firstdayofweek' it
takes the default value, which happens to be vbUseSystem - so if the system
settings vary on the two computers, the result is different.

If this is what is happening, you should be able to fix it by changing the
VBA function call to be
WeekdayName(Weekday(StartDate, vbSunday), True, vbSunday)
 
H

Harald Staff

Hi

If you just want the day name, use this simple approach instead:
Format(StartDate, "ddd")
or
Format(StartDate, "dddd")

HTH. Best wishes Harald
 

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