DateSerial in VBA...confused

  • Thread starter Thread starter Mark
  • Start date Start date
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
 
You shouldn't need the call to day(), just:

DateSerial(Year(Date), Month(Date), 3)
 
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)
 
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)
 
Back
Top