Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET ticks to Oracle date 1

Status
Not open for further replies.

tpremore

Technical User
Apr 13, 2001
22
US
I have a number that represents the value you get when you look at a .NET System.DateTime .Ticks property. This number is 633325517040000000. The problem is that I have this in an oracle table and I want to get a human readable date from it using PL SQL. I no longer have access to the handy .NET System.DateTime object that easily will convert this to something readable. Any Ideas, smart people? :)
-Travis
 
Hmmm...

According to
[Ticks are] the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001.

So there are 10 million ticks in a second. To convert ticks into an Oracle date, you just have to work out how many days that number of ticks is, and add it to the start date. Something like this:
Code:
SELECT TO_DATE('01-jan-0001','dd-mon-yyyy') +
       ticks/(10000000 * 60 * 60 * 24) ticks_date
FROM   dual
Obviously, you could put that calculation into a PL/SQL function if you wanted to.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Awesome, thanks Chris. It doesn't seem to work perfectly for all times from the year 0001 to modern times, but for everything back at least as far as 1595 it's only off by 2 days. And it's exactly 2 days, so I just start with Jan 3 0001 and I'm happy. It's probably some crazy Gregorian/Julian calender thing that there is a perfectly good explanation for so I'll leave it at this - I have a workable solution! Thanks,
Travis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top