DateSerial in VBA...confused

M

Mark

I have the following lines of code in a function:

Function curr_date_test()
Dim dt1 As Date
dt1 = DateSerial(Year(Date), Month(Date), day(3))
Debug.Print dt1
End Function

The value returned for dt1 is 2/2/2006. Why isn't it returning
2/3/2006?

Thanks,
Mark
 
G

Gina via AccessMonster.com

You shouldn't need the call to day(), just:

DateSerial(Year(Date), Month(Date), 3)
 
J

James A. Fortune

Mark said:
I have the following lines of code in a function:

Function curr_date_test()
Dim dt1 As Date
dt1 = DateSerial(Year(Date), Month(Date), day(3))
Debug.Print dt1
End Function

The value returned for dt1 is 2/2/2006. Why isn't it returning
2/3/2006?

Thanks,
Mark

When I run MsgBox(CDate(3)) I get 1/2/1900. So day(3) = 2. You should
use 3 in place of day(3).

James A. Fortune
(e-mail address removed)
 
G

Guest

day() takes a date
day(3) is the day when the date is 3

Access/VBA counts the days from December 31, 1899.

cdate(3) is January 2nd, 1900
cdate("January 2nd, 1900") is 3

day(cdate("January 2nd, 1900")) is 2

(david)
 

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