Siva
Siva

Reputation: 581

How can convert a datetime to double?

How can convert a datetime to double?

Upvotes: 7

Views: 11919

Answers (2)

BornToCode
BornToCode

Reputation: 10213

A better approach than ToOADate is to use this:

double timestamp = DateTime.UtcNow.Ticks;

See this post where precision is lost when doing DateTime.Now.AddTicks(1000).ToOADate(), if the example there were changed to (double)DateTime.Now.AddTicks(1000).Ticks the precision is not lost.

Upvotes: 1

Ritch Melton
Ritch Melton

Reputation: 11598

var converted = DateTime.Now.ToOADate();

Upvotes: 13

Related Questions