vba date function

  • Thread starter Thread starter ddnguyen
  • Start date Start date
D

ddnguyen

Hi,
I don't really know what is wrong with this function, might be
something very basic.
I had a vba function that reads date in form 19501220 and spits out a
date serial 18617, which could be reformat in excel like 12/20/1950

The vba function is:

Public Function SDate(strDt As Long)
If strDt <19000101 Then SDate = 0: Exit Function
SDate = DateSerial(Left(strDt, 4), Mid(strDt, 5, 2), Right(strDt, 2))
End Function

The problem is from date 19000101 to 19000229 the function produces one
day in advance, e.g.
19000101 (1st day) will be 1/2/1900
19000229 (day 61th) will be 3/1/1900
From 19000301 upto present date the function gives correct date.

Thanks for all clarifications.
Dailoc
 
Hi

For compatibility reasons, Excel has chosen to believe that 1900 was a leap
year. VBA knows it wasn't.

HTH. Best wishes Harald
 
Excel itself treats 1900 as a Leap Year. VBA doesn't. Excel is incorrect
and supposedly intentionally introduced this problem to be consistent with
Lotus 1-2-3 which had the problem.
 

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

Similar Threads

Automatic date formating 2
Exel.Exe lingering in Task Manager 2
VBA Dates help 3
Combining Text and Date function in VBA 4
excel and dates 2
Problem with dates 1
index function in vba 3
Very Simple Date Issue 4

Back
Top