Dates and times in Excel are represented by real numbers. For example a date that is displayed in Excel as "Jan 1 2013 12:00 PM" is stored as the number 41275.5.
The integer part of the number stores the number of days since the epoch, which is generally 1900, and the fractional part stores the percentage of the day.
A date or time in Excel is just like any other number. To display the number as a date you must apply an Excel number format to it. Here is an example:
The members of the lxw_datetime struct and the range of their values are:
|year||1900 - 9999|
|month||1 - 12|
|day||1 - 31|
|hour||0 - 23|
|min||0 - 59|
|sec||0 - 59.999|
Dates in Excel do not support timezones and the maximum resolution of times is milliseconds.
If dates or times are required without the other you should initialize the unrequired values to
The output from this program is the same as the previous example.
Dates can be formatted using any of the date formats supported by Excel. Here is a longer example that shows the same date in a several different formats:
Next: Working with Charts