Devon Quick
Devon Quick

Reputation: 348

Trying to convert a decimal to datetime either in SQL Server or C#

I have this decimal 411409629.172566 and it equals 01/14/2014. I'm working on converting some data from a competitor software and in there SQLite DB, the dates are stored as decimals like that.

In there software the date is what I put above. I have been trying to figure this date out for a couple days now. how do I convert that decimal to that date?

Upvotes: 0

Views: 1025

Answers (2)

har07
har07

Reputation: 89325

The following prints "1/14/2014" in my console :

new DateTime(2001, 1, 1).AddSeconds(411409629.172566).ToShortDateString()

or using equivalent SQL server syntax :

select dateadd(ss, 411409629.172566, '01-01-2001') as 'date'

... but without more samples we can't be sure this always do the correct conversion.

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172628

You may try like this:

System.DateTime dt = new System.DateTime(1970, 1, 1).AddSeconds(yourDecimalValue);

Upvotes: 0

Related Questions