Discussion:
Convert Datetime to int c#
(too old to reply)
Patrick Chung
2015-12-03 10:27:49 UTC
Permalink
We need to convert datetime to int in c# for example when we want to add new series of the data in chart control to previously added series of data where x axis was given in datetime format. If in this additional data series we have X axes values as integers, chart control will automatically convert this X axses data into datetime format. Problem is that we indexed X axes data in order to appearance (1,2,...), chart will convert this data into date 1900/1/1, 1900/1/2 and so forth.

Read more:

http://www.cirvirlab.com/index.php/c-sharp-code-examples/convert-datetime-to-int-c.html
Arne Vajhøj
2015-12-05 01:33:36 UTC
Permalink
Post by Patrick Chung
We need to convert datetime to int in c# for example when we want to
add new series of the data in chart control to previously added
series of data where x axis was given in datetime format. If in this
additional data series we have X axes values as integers, chart
control will automatically convert this X axses data into datetime
format. Problem is that we indexed X axes data in order to appearance
(1,2,...), chart will convert this data into date 1900/1/1, 1900/1/2
and so forth.
http://www.cirvirlab.com/index.php/c-sharp-code-examples/convert-datetime-to-int-c.html
Why copy a SO answer over in a blog?

Especially since the SO answer is not that good.

(int)(theDate.Date - new DateTime(1900, 1, 1)).TotalDays + 2

can be done as:

(int)theDate.ToOADate()

Arne

Continue reading on narkive:
Loading...