View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default DateValue gets wrong date number

On Thu, 14 May 2009 10:27:30 -0400, "Bernie Deitrick" <deitbe @ consumer dot
org wrote:

Stuart,

VBA dates use US default - mm/dd/yyyy, not dd/mm/yyyy - as the first interpretation of the date
string. If that fails (the dd value is 13 or higher), then it tries dd/mm/yyyy.


Bernie,

I've seen this written a bunch of times and never checked it out. But today I
did and, at least on my system (VBA 6.5), Datevalue behaves exactly as
documented.

According to HELP, "DateValue recognizes the order for month, day, and year
according to the Short Date format you specified for your system. "

So I did the following in the Immediate window:

?format(datevalue("01/04/2009"),"dd-mmm-yyyy")

With my default US settings, the result was:

04-Jan-2009

However, when I changed the Short Date format in my regional settings to
d/M/yyyy, the result was:

01-Apr-2009

I then changed it again to UK settings, and again got the

01-Apr-2009

result.

So it seems to me there is something else going on than VBA date handling
issues.
--ron