PC Review


Reply
Thread Tools Rate Thread

Convert to/from Excel date

 
 
David Thielen
Guest
Posts: n/a
 
      4th Apr 2008
Is there any code or an article that lists exactly how to convert to/from a
datetime as stored in an Excel XLSX file and
year/minth/day/hour/minute/second?

Also, from playing with it, it appears that Excel thinks 2/29/1900 existed
(it was not a leap yer).

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      4th Apr 2008
Not to sure what you mean when you say convert to from date. Convert to what?
You can use the text function to get a date converted to text.

=Text(A1, "yyyy/mm/dd/hh/mm/ss")

As for the leap year issue that is not a bug in XL. It is a bug in Lotus
123. For XL to be compatable it had to make the same mistake as Lotus.
--
HTH...

Jim Thomlinson


"David Thielen" wrote:

> Is there any code or an article that lists exactly how to convert to/from a
> datetime as stored in an Excel XLSX file and
> year/minth/day/hour/minute/second?
>
> Also, from playing with it, it appears that Excel thinks 2/29/1900 existed
> (it was not a leap yer).
>
> --
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
>
> Cubicle Wars - http://www.windwardreports.com/film.htm
>
>

 
Reply With Quote
 
David Thielen
Guest
Posts: n/a
 
      4th Apr 2008
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.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"Jim Thomlinson" wrote:

> Not to sure what you mean when you say convert to from date. Convert to what?
> You can use the text function to get a date converted to text.
>
> =Text(A1, "yyyy/mm/dd/hh/mm/ss")
>
> As for the leap year issue that is not a bug in XL. It is a bug in Lotus
> 123. For XL to be compatable it had to make the same mistake as Lotus.
> --
> HTH...
>
> Jim Thomlinson
>
>
> "David Thielen" wrote:
>
> > Is there any code or an article that lists exactly how to convert to/from a
> > datetime as stored in an Excel XLSX file and
> > year/minth/day/hour/minute/second?
> >
> > Also, from playing with it, it appears that Excel thinks 2/29/1900 existed
> > (it was not a leap yer).
> >
> > --
> > thanks - dave
> > david_at_windward_dot_net
> > http://www.windwardreports.com
> >
> > Cubicle Wars - http://www.windwardreports.com/film.htm
> >
> >

 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      4th Apr 2008
On Thu, 3 Apr 2008 16:54:00 -0700, David Thielen <(E-Mail Removed)> 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 don't know about "tested code", but the conversion should be pretty
straightforward, including adding in a day for February 29, 1900. (I have read
that this mistake started with Lotus 1-2-3, which predated Excel, and that MS
incorporated this error into Excel for "compatibility".

Excel stores dates/times as days and fractions of a day. If the worksheet was
using the 1900 date system, then 1 = 1 Jan 1900. And 12 noon on that day would
be represented as 1.5.

If using the 1904 date system, then 1 = 2 Jan 1904 (0 = 1 Jan 1904).

(Date1904 is a Workbook property, but I don't know how that would be stored in
the XLSX file).
--ron
 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      4th Apr 2008
On Thu, 3 Apr 2008 16:54:00 -0700, David Thielen <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert date (m/dd/yyyy) in text format into an excel recognised date Rob P Microsoft Excel Programming 3 30th Apr 2010 12:40 AM
Re: How to convert Gregorian date into Hijri Date in Excel 2007? James Silverton Microsoft Excel Misc 0 6th Feb 2009 03:59 PM
How to convert Gregorian date into Hijri Date in Excel 2007? Ahmed Microsoft Excel Misc 1 6th Feb 2009 03:49 PM
VBA convert day and date from text string to Excel date Max Bialystock Microsoft Excel Programming 5 14th May 2007 04:54 AM
How to convert Excel serial date into Access date format? RADO Microsoft Access 2 27th Dec 2003 12:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:37 PM.