Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

ExcelDateSystemConverter

OfficeIMO.Excel

Namespace
OfficeIMO.Excel
Assembly
OfficeIMO.Excel
Source revision
273d35d5ba8a with working tree changes
Modifiers
static

Converts dates to and from Excel serial values using the workbook's configured date system.

Inheritance

  • object
  • ExcelDateSystemConverter

Remarks

A serial counts days, and its whole part is the day Excel reports for it. Serials hold whole milliseconds: values are stored truncated to the millisecond, so a time just before midnight stays on its own day, and serials read back rounded to the nearest millisecond, never past the last millisecond of the serial's day. The time always comes from the serial's own fraction; a date system's epoch moves only whole days, as integer arithmetic, so the 1904 offset never changes how a fraction rounds.

Methods

public static DateTime FromSerial(double serial, ExcelDateSystem dateSystem) #

Converts an Excel serial value from the selected date system to a date. In the 1900 system, serial 60 denotes Excel's fictitious February 29 and maps to February 28 because DateTime cannot represent it. Negative serials extend the epoch backwards in both systems, December 31, 1899 or January 1, 1904, with fractional values representing elapsed portions of a day.

Parameters

serial double required
dateSystem OfficeIMO.Excel.ExcelDateSystem required

Returns

DateTime
public static double ToSerial(DateTime value, ExcelDateSystem dateSystem) #

Converts a date to the serial value used by the selected Excel date system. Dates before serial 0, December 31, 1899 in the 1900 system and January 1, 1904 in the 1904 system, extend the epoch backwards as negative serials in both systems. Excel shows those cells as ####; OfficeIMO reads them back as the same date.

Parameters

value System.DateTime required
dateSystem OfficeIMO.Excel.ExcelDateSystem required

Returns

double

Fields

public const double Date1904OffsetDays #

Number of days between the Excel 1900 and 1904 date-system epochs.

Value: 1462