Live SpreadsheetGear API Samples
Workbook Miscellaneous DateTimes and Excel Serial Numeric Dates
Excel and SpreadsheetGear both store dates and date/times as serial numeric values, where a serial date value of 0 corresponds to the date "January 0, 1900 12:00:00 AM".* Dates prior to this are not supported. A serial date consists of two parts:
- The whole number portion of a serial date represents the number of days elapsed since "January 0, 1900". For instance, a date of December 31, 2020 is the serial number 44196.
- The fractional portion of a serial date represents the time of day. For instance the time 6:00 PM / 18:00 is 0.75)
In order for a cell to display its value as a date instead of the underlying serial numeric value, the cell's IRange.NumberFormat must be set to a date or date/time format such as "m/d/yyyy h:mm AM/PM".
SpreadsheetGear offers helper methods to convert .NET DateTime values to serial dates and vice-versa. The below sample code demonstrates the use of these methods.
*NOTE: although uncommon, Excel files do offer an alternative Date1904 mode where a serial numeric date value of 0 corresponds to January 1, 1904. This mode is typically not used for the most part, but SpreadsheetGear does support it if a workbook uses it.
Run This Sample
Render Image
Generate an image representation of the results of this sample, which uses the SpreadsheetGear.Drawing.Image class to convert ranges, charts and shapes to images.
Download File
Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.