![]() |
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 |
vba date function
Hi
For compatibility reasons, Excel has chosen to believe that 1900 was a leap year. VBA knows it wasn't. HTH. Best wishes Harald skrev i melding oups.com... 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 |
vba date function
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. -- Regards, Tom Ogilvy wrote in message oups.com... 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 |
All times are GMT +1. The time now is 06:21 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com