DatePart function

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?
 
D

Douglas J. Steele

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#)
 

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