Reputation: 13
I'm completely stumped -
Using the Weekday()
function in vba is returning the incorrect weekday, while using it within a sheet in Excel is returning the correct weekday. Specifying or omitting the start-of-week arguments does not seem to be making any difference either.
The system clock (which is what I assume it uses for 'today') has not been changed. In fact, I don't even have access to change it.
This is what my immediate window in VBA returned:
Print Weekdayname(Weekday(today),False)
Saturday
Print Weekday(today)
7
Print Application.WorksheetFunction.Weekday(today)
7
Print Weekday(6/5/2014)
7
Print Weekday(6/13/2014)
7
The excel sheet, on the other hand, returns 5 for these formulas:
=WEEKDAY(TODAY())
=WEEKDAY(DATEVALUE("06/5/2014"))
Any help would be greatly appreciated!
Edit:
I am using Excel 2010 on Windows 7.
Upvotes: 1
Views: 5106
Reputation:
You try to display the weekday of a Date serial number that's result of the calculation 6/5/2014
(i.e. 6 divided by 5 then divided by 2014).
If you want to use literal values of type Date, try in your Immediate window:
?Weekday(#6/5/2014#)
Please note the difference between this and:
?Weekday(6/5/2014)
Upvotes: 3
Reputation: 1195
The problem is "today" will not return anything. Use "now":
Weekdayname(Weekday(Now),False)
Also, for your last functions where you are inputting the date, you need to put it in quotes:
Weekday("6/5/2014")
Upvotes: 5