Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Function to lookup date on tab in excel and populate date on calen | Excel Worksheet Functions | |||
Difference betwen Excel Date () Function and System Date | Excel Worksheet Functions | |||
SUMIF within date range as a function of today()'s date | Excel Worksheet Functions | |||
Date Function formula that will return the date of a specific week | Excel Worksheet Functions | |||
Calculating days between current date and a date in future NETWORKDAYS() function | Excel Worksheet Functions |