Convert to/from Excel date
On Thu, 3 Apr 2008 16:54:00 -0700, David Thielen wrote:
Now that's what I call being serious about compatibility :)
I have some C# code that parses an XLSX file. So it reads that the cell is
formatted as a date_time and has a value of 12345.678 - I need to convert
that to year, month, day, hour, second, minute to create a DateTime object.
And then I have to do the reverse when creating an XLSX output file.
One thing I have learned about dates - it is very very difficult to get it
right (Lotus 123 being a good example). So if there is tested code that does
this somewhere, it would be very helpful.
Especially if there are other purposful errors in addition to the 2/29/1900
one.
I forgot to mention that, within VBA, CDate will convert your value to a date,
but the VBA date system does not include Feb 29, 1900
In the Immediate Window:
?cdate(12345.678)
10/18/1933 4:16:19 PM
Since the VBA date system does not include Feb 29, 1900, it starts off with
1 = 12/31/1899
So there is a one day difference until Mar 1, 1900 compared with Excel; then
they agree.
--ron
|