Algorithm for converting Adabas P12 value to date time (without Natural)

Hi

I’m a complete beginner in terms of Natural programming, but here’s my problem: We have replicated an Adabas database to Microsoft SQL Server. Some of the tables contain timestamp fields, which in Adabas are P12 values. These can be converted to date time through an edit mask in Natural, but what is the algorithm/procedure for doing so? I would like to do it in SQL Server (or potentially C# on the Microsoft .NET platform).

Best regards,
Patrick

Patrick,

before you go for decoding it yourself, how are you replicating these files,
there may be ways to transcode on the way down.

Best regards,

   Wolfgang

Perhaps you can reverse-engineer a formula with these starting blocks. Time is a count over the number of tenths of a second since a point of origin, which if working backwards under the current Gregorian system should be about January 1, year 0 (which never happened).

A couple of milestones should illustrate this:

631138176000 = 1/1/2000

630822816000 = 1/1/1999

599581440000 = 1/1/1900

Some basic conversions:

1 min = 600
1 hr = 36000
1 day = 864000
1 yr (365) = 315360000
1 yr (366) = 316224000

Including the 24 leap-year days between 1/1/1900 and 1/1/2000 (1900 was not a leap year), back-checking the time since 1900 to 2000, 100315360000 + 24864000 = 31556736000 which is the difference between two dates in time format.

Extending this, as every 4 years is a leap year, but years divisible by 100 are not unless they are divisible by 400 (then they are again), you have 488 leap years and 1525 normal years to Jan 1, 2013. The calculation 488316224000 + 1525315360000 = 635241312000, which is EXACTLY how Jan 1, 2013 at 00:00:00 is stored.

Hope this helps!

-Brian

Thank you both for your answers.

We didn’t have the time to figure out how to convert P12 values to datetime in the replication tools, but we instead used an approach similar to the one suggested by Brian Johnson and made it work in the end (and ran into the fact that the earliest date that SQL Server can handle is 1753-01-01).

-Patrick

On Natural/Adabas it is 1582-01-01, that’s the year the gregorian calendar was adopted by some european countries.
In 1753 the gregorian calendar was introduced in GB…

http://en.wikipedia.org/wiki/Gregorian_calendar#Timeline