Convert SQLDateTime DayTicks back to DateTime value

391 Views Asked by At

I have a date value stored as an integer in a database that was created using the SQLDateTime DayTicks function. How can I reverse engineer that integer value back into a DateTime value?

2

There are 2 best solutions below

0
On BEST ANSWER

You will lose the time portion of the date unless you also have timeTicks floating around somewhere. This will convert the dayTicks back into a DateTime:

SqlDateTime sdt = new SqlDateTime(dayTicks, 0);
DateTime dt = sdt.Value;
1
On

Try this:

DateTime result = new DateTime(ticks);

There is an overload of the DateTime constructor that takes the number of ticks.