Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how do I convert julian to gregorian date in abap example code?

Former Member
0 Kudos

Need some assistance

8 REPLIES 8

horst_keller
Product and Topic Expert
Product and Topic Expert

ABAP counts days from 00010101. The switch from Julian to the Gregorian calendar is handled in the conversion rules from numeric to date and vice versa as follows:

  • Converting 577,736 to a target field of type d produces 4.10.1582, and converting 577,737 produces 15.10.1582. The dates for the intermediate days that were lost during the switch from the Julian to the Gregorian calendar cannot be produced by assigning a numeric value to a target field of type d.
  • The conversion of a date into the number of days since 01.01.001 is designed in such a way that the transition from the Julian to Gregorian calendar is respected: 4.10.1582 produces the number 577,736 and 15.10.1582 produces 577,737. Converting the dates of the nonexistent days between 5.10.1582 and 14.10.1582 produces the same result as converting the existing days from 15.10.1582 to 24.10.1582.

So ABAP does it itself. What should a conversion between Julian and Gregorian calendar be about? If you want to calculate anything, the above rules should be sufficient.

Jelena
Active Contributor
0 Kudos

Rather curious about the story behind this question... Are there businesses using Julian calendar? Some Orthodox Church runs SAP? Need to run the financial reports for the 15th century? Some ABAP trainer is pulling your leg?

Scratching my head here why would this be possibly needed...

Former Member
0 Kudos

It's not for any business purpose. I was just attempting too write some practice code that converts Julian calendar date to the Gregorian calendar. I'm a junior developer and trying work on my skills.

Sandra_Rossi
Active Contributor

I fully agree with Horst answer. But just to say about the nature of the question: converting a date from Julian calendar to Gregorian is mostly non-sense: the Gregorian calendar has replaced the Julian calendar, officially from October 5th 1582, as Horst says (in many countries, and adopted by others later).

If your question is more about "if the Julian calendar had continued in some countries after 4.10.1582, how could we translate a Julian date after 4.10.1582 into Gregorian calendar?" then:

  • (Fictious) Julian 5.10.1582 would be Gregorian 15.10.1582 (+10 days)
  • It's >= 10 days for all next days, as leap years exist every 100 years (except every 400 years) in Julian calendar; Jul 20.03.2017 would be Greg 02.04.2017 i.e. +13 days)
  • Etc.
  • the ABAP date calculations are explained by Horst above

Jelena
Active Contributor

IMHO you need better examples to polish your skills. There is no point choosing a conversion that makes no sense (as Sandra also pointed out). Now converting, say, a calendar date into a fiscal period - that's something you are likely to actually use in real life.

Why not just search for the date conversion questions on SCN and then attempt solutions? Although realy, date conversion is usually a simple FM or method call, so hardly any skill is needed for that (IMHO, again).

Good luck.

horst_keller
Product and Topic Expert
Product and Topic Expert

You could give the link where you copied from, e.g. http://aa.usno.navy.mil/faq/docs/JD_Formula.php

matt
Active Contributor
0 Kudos

Copying other people's work is plagiarism and strictly forbidden. It can lead to account suspension.

horst_keller
Product and Topic Expert
Product and Topic Expert

Say, is the question about Julian Day and not about Julian Calendar? That at least would make some sense.

According to http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html the astronomer´s julian day was even invented by a different Julius (not good ol´ Gaius Julius Cesar).

Googling the web you find some pages that present formulas and code snippets that show how to convert between Gregorian Dates and Julian Days.

All you have to do is to write some basic ABAP that implements these formulas.