View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] ddnguyen@stpaultravelers.com is offline
external usenet poster
 
Posts: 1
Default vba date function

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