Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

CellValue.FromDateTime(DateTime, Boolean) Method

Converts the DateTime object to a cell value using the specified date system.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

public static CellValue FromDateTime(
    DateTime value,
    bool use1904DateSystem
)

Parameters

Name Type Description
value DateTime

A DateTime object that specifies a date and time value to be converted to a cell value.

use1904DateSystem Boolean

true, if the 1904 date system is used; otherwise, false.

Returns

Type Description
CellValue

A CellValue object.

Remarks

Dates are stored in cells as numbers called serial values. A serial value is an integer that is the number of elapsed days from the first day in the date system. SpreadsheetControl supports the 1900 and 1904 date systems for serial values. For details, refer to Dates and Times in Cells.

The CellValue.NumericValue property of the cell value object returns the number contained in a cell (a serial value), and the CellValue.DateTimeValue property returns the corresponding date in the date system used in the workbook (the Workbook.DocumentSettings.Calculation.Use1904DateSystem property).

Use the FromDateTime method to get the CellValue object from the DateTime object. The date’s serial value is calculated based on the passed use1904DateSystem parameter value.

For example, consider the date 12/17/2012. The table below demonstrates which serial values this date is represented by in each date system, how the date can be assigned to a cell in each date system, and how the date displayed depends on the date system applied in the workbook.

Date System to Input Date

Serial Value of 12/17/2012

Input Date

Use1904DateSystem = false

Use1904DateSystem = true

1900

41260

cell.Value = new DateTime(2012, 12, 17)

cell.Value = CellValue.FromDateTime(new DateTime(2012, 12, 17), false)

CellValue.NumericValue = 41260

CellValue.DateTimeValue = {12/17/2012 12:00:00 AM}

CellValue.NumericValue = 41260

CellValue.DateTimeValue = {12/18/2016 12:00:00 AM}

1904

39798

cell.Value = CellValue.FromDateTime(new DateTime(2012, 12, 17), true)

CellValue.NumericValue = 39798

CellValue.DateTimeValue = {12/16/2008 12:00:00 AM}

CellValue.NumericValue = 39798

CellValue.DateTimeValue = {12/17/2012 12:00:00 AM}

See Also