DatePart function

  • Thread starter Thread starter Ha
  • Start date Start date
H

Ha

I want to convert a date into a numeric value.
I tried using the DatePart function in a textbox.
=DatePart("y",#3/13/1997#)

Result show 72 when it should be 35502.

I want to convert the date into days. How do I do that?
 
It's returning 72 because Mar 13 was the 72nd day of the year. DatePart
won't return the number of days since 30 Dec, 1899: it looks at the given
date, and returns what day it represents, what month, etc.

To get the fact that 13 Mar, 1997 is 35502 days since 30 Dec, 1899, try
either

CLng(#3/13/1997#)

or

DateDiff("d", #12/30/1899#, #3/13/1997#)

or

DateDiff("d", 0, #3/13/1997#)
 
Back
Top