Strange Date issue

J

John Smith

Hi all,

I'm messing around with dates and tried the following off the MS site :-

Dim dteDate As Date
dteDate = #4/5/1999#
Debug.Print day(dteDate)

the day(dteDate) is throwing an error as VBA thinks its referencing and
array.. it should give the value '4'.

any ideas?

JS
 
D

Dave

it works for me under excel xp. the lower case 'd' on day would make it
look like it does not recognize it as the built in Day function. have you
maybe defined a variable 'day' somewhere that is confusing it??

for instance:
Dim day As Integer
Dim dteDate As Date
dteDate = #4/5/1999#
Debug.Print day(dteDate)
fails because it wants day to be an array not an integer.
 
S

Steve Rindsberg

Hi all,

I'm messing around with dates and tried the following off the MS site :-

Dim dteDate As Date
dteDate = #4/5/1999#
Debug.Print day(dteDate)

the day(dteDate) is throwing an error as VBA thinks its referencing and
array.. it should give the value '4'.

Or 5, depending on your local settings.

Works ok here in PPT2000, fwiw.
 
D

Dave

that is true, mine returns 5 on stateside settings since we use mm/dd/yyyy
by default.
 
J

John Smith

Ok - checked my code - I had set a date variable elsewhere which confused
it.
By the way even though my system is UK it gives me US dates - is there a way
I can change this from code (I'm using format to force correct output at the
moment) ?

Cheers for the replies

JS
 
S

Steve Rindsberg

Ok - checked my code - I had set a date variable elsewhere which confused
it.
By the way even though my system is UK it gives me US dates - is there a way
I can change this from code (I'm using format to force correct output at the
moment) ?


Try it this way:

Dim dteDate As Date
'dteDate = #4/5/1999# - forces VB to us US-style dates
dteDate = "4/5/1999" - lets VB handle date based on your local settings
Debug.Print day(dteDate)

Pretty sure I have that right.
 

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