0

Possible Duplicate:
How do I read a date in Excel format in Python?

I am reading values from a .XLS(excel) file.While reading a date field,i am getting a float value like 40374.What i need is to convert this float value into date.Please help.

Thanks in advance!!!!

Community
  • 1
  • 1
Alchemist777
  • 1,621
  • 5
  • 21
  • 31
  • 1) That is an integer value. 2) When you open the file in Excel, does it show "40374", or a date? If it shows 40374, it could represent anything (see if you notice a pattern, like things 1 day apart being +/- 1 away; or check the code of the program which created the data, or the documentation thereof; it might be days-since-some-specific-day). If it shows a date, then you can figure this out yourself by playing around with the data. – ninjagecko May 14 '12 at 06:41

1 Answers1

2

Dates in excel are represented by the number of days since 1/1/1900. So 40374 is 40,374 days after 1/1/1900, or July 15, 2010

Also I believe that if there is anything after the decimal point, this represents a fraction of a day.

so 40374.0 would be 7/15/2010 at midnight, .5 would be noon, .75 is 6pm, etc.

Tim
  • 35,413
  • 11
  • 95
  • 121
  • You beat me to it. [You could use a link to the relevant Excel documentation, though.](http://support.microsoft.com/kb/2140940) – Li-aung Yip May 14 '12 at 06:45
  • 40,374 days after January 1, 1900 would be July 17, 2010. You need to subtract 1 (off-by-one error), and you need to account for February 29, 1900, in order to get July 15, 2010. – Josh Lee May 14 '12 at 06:48
  • @Li-aungYip: That link appears to be broken. – Tim Pietzcker May 14 '12 at 07:00
  • 1
    @TimPietzcker: Oops. [Here it is again, without the trailing zero...](http://support.microsoft.com/kb/214094) – Li-aung Yip May 14 '12 at 07:07