View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Incorrect results of Weekdayname(Weekday... function???

On Wed, 2 Jun 2004 08:05:30 -0500, Kobayashi
wrote:

I'm trying to determine the day of the week for a date, which will then
be used in an IF argument. However, when I put the following in the
debug pane I get 'Thursday' as the result, when clearly today is
Wednesday!???

I'm actually using a variable which contains the date of "26/05/2004",
but this doesn't work either?

I'm using Excel 2000 with UK regional settings.

?weekdayname(weekday("02/06/2004"))

I'm sure this is going to be something very simple and slightly
embarassing for me when resolved but help would be appreciated!

Very confused!

Adrian



Here's something very interesting and I don't understand it.

With US regional settings:

?weekdayname(weekday(dateserial(2004,6,2)))
Wednesday

With UK regional settings:

?weekdayname(weekday(dateserial(2004,6,2)))
Thursday

but, still with UK regional settings:

?weekdayname(weekday(dateserial(2004,6,2),vbSunday ),,vbSunday)
Wednesday

?weekdayname(weekday(dateserial(2004,6,2)),,vbSund ay)
Wednesday

?weekdayname(weekday(dateserial(2004,6,2),vbUseSys temDayOfWeek),,vbUseSystemDayOfWeek)
Wednesday

?weekdayname(weekday(dateserial(2004,6,2)),,vbUseS ystemDayOfWeek)
Thursday

and finally, with UK settings:

?weekdayname(1)
Monday

but with US settings:

?weekdayname(1)
Sunday

So it seems that the safest method is to both generate a date serial number
from an unambiguous entry; and also to explicitly specify the first day of the
week for both the weekday and weekdayname arguments.


--ron