How to Convert Between Julian Day and Gregorian Date?

In summary, The Gregorian calendar is based on a 400 year cycle and the conversion between Julian day and Gregorian date involves finding the number of elapsed days and years within these cycles. The formula used is derived from a relatively simple pattern and involves using the minimum of two numbers to account for exceptions in leap years. This minimum function may not be a standard function in all programming languages.
  • #1
lewis198
96
0
Hi guys, I have another weak problem here if you would care to help, please.

I am trying to convert between the julian day and the gregorian date, and I found a eally good website:http://www.ortelius.de/kalender/calc_en.php

The only problem is that when I run into the centennial cycle another factor comes into play. Here is the text:

Computing the Gregorian date of a given JD

The Gregorian calendar is based on a 400 year cycle, after which the days of the week and the sequence of leap years repeat. Each 400 year cycle consists of four 100 year cycles of which the first three end with a common year, while the last cycle ends with a leap year. Every 100 year cycle contains 4 year cycles, of which the first three years are common years followed by a leap year. The irregular and unequally distributed month lengths make it difficult to find an algorithm with only few exceptions.

The formulas are derived according to a relatively simple pattern. First, the JD is increased by 32044. The result N1 ist the number of elapsed days since 1 March 4801 BCE, Gregorian. The division of this number N2 by 146097 days gives the number of elapsed 400 year cycles, each of them containing 146097 days. The remainder of this division (N3) shows, how many days of the current 400 year cycle have elapsed already. Dividing N3 by 36524 days (= 100 years) gives us the number of the elapsed 100 year cycles within the current 400 year cycle. The last day of the last 100 year cycle, though, has to be treated exceptionally, this day being counted as the first day of a fifth 100 year cycle of the current 400 year cycle. This exception is made by simply taking the minimum of 3 and the result of the foregoing division. The last year of the last 100 year cycle is a leap year, which makes it one day longer than the last years of the first three 100 year cycles of the current 400 year cycle. (E. g., 29 February 2000 is such an exceptional day.) For the same reason, one cannot simply take the remainder of the division to compute the elapsed days within the current 100 year cycle, this remainder becoming 0 in case of the "last day", see the equation for the calculation of N4 and N5.

A four year cycle ends with a leap year, which is one day longer than each of the three preceeding common years. Therefore, the computation of the number of elapsed years within a four year cycle (N8) and of the number of elapsed days within the current year (N9) is done the same way.

N6 is the number of elapsed 4 year cycles within the current 100 year cycle. The last 4 year cycle of each 100 year cycle normally is one day shorter than the other four year cycles, making similar exceptions as mentioned above unnecessary.

The number of the day within the current year is N9. Note, that "year" means "adjusted year", beginning with the third month March and ending with the fourteenth month February. The computation of the number of the month (N10) from N9 is done with a formula derived empirically by dividing N9 by the mean length of a month and some trying.

The result of all this are the following equations.

N1 = JD + 32044
N2 = int(N1 / 146097)
N3 = N1 mod 146097
N4 = min(3 ; int(N3 / 36524))
N5 = N3 - 36524 · N4
N6 = int(N5 / 1461)
N7 = N5 mod 1461
N8 = min(3 ; int(N7 / 365))
N9 = N7 - 365 · N8
N10 = int((111 · N9 + 41) / 3395)
D = N9 - 30 · N10 - int((7 · (N10 + 1)) / 12) + 1
M' = N10 + 3
Y' = 400 · N2 + 100 · N4 + 4 · N6 + N8 - 4800
M = ((M' + 11) mod 12) + 1
Y = Y' + int(M' / 13)

The determination of the minimum of two numbers can be put in a more formal way. The formulas for N4 and N8 can be substituted by

N4 = int(N3 / 36524) - int(N3 / 146096)
N8 = int(N7 / 365) - int(N7 / 1460)

The underlined part is what I don't understand: what on Earth does that min(3 stuff mean? and what would happen if you don't use it?

Thanks for reading this.
 
Last edited by a moderator:
Mathematics news on Phys.org
  • #2
I imagine it means take the mimimum of '3' and N7/365.
ie if N7 is greater than 121 use 3 otherwise use N7/363.

min isn't a standard function in 'c' but it is in many basics
 
  • #3



Hi there, it seems like you are trying to convert between the Julian day and the Gregorian date. The website you found is a good resource, but you are having trouble understanding the algorithm used for the conversion. Let me try to explain it to you.

Firstly, the Gregorian calendar is based on a 400 year cycle, where each cycle consists of four 100 year cycles. The first three end with a common year, while the last one ends with a leap year. Within each 100 year cycle, there are four 4-year cycles, with the first three being common years and the last one being a leap year.

To calculate the Gregorian date from a given Julian day, the algorithm follows a specific pattern. First, the Julian day is increased by 32044. This gives us a number (N1) which represents the number of days elapsed since 1 March 4801 BCE in the Gregorian calendar.

Next, we divide N1 by 146097 (the number of days in a 400 year cycle) to get the number of elapsed 400 year cycles (N2). The remainder of this division (N3) tells us how many days have elapsed within the current 400 year cycle.

Similarly, we divide N3 by 36524 (the number of days in a 100 year cycle) to get the number of elapsed 100 year cycles (N4). However, the last day of the last 100 year cycle is treated exceptionally, as it is counted as the first day of a fifth 100 year cycle. This is taken into account by using the minimum value between 3 and the result of the division.

The same approach is used to calculate the number of elapsed 4 year cycles (N6) and the number of elapsed days within the current year (N9).

The number of the day within the current year is N9. To calculate the month (N10), a formula derived empirically is used.

Finally, the equations are used to determine the final values for the day, month, and year. The min(3, int(N3/36524)) and min(3, int(N7/365)) parts in the equations for N4 and N8 mean that if the result of the division is greater than 3, it will be adjusted to 3. This is necessary to account for the exceptional treatment of the last day of the
 

Related to How to Convert Between Julian Day and Gregorian Date?

Question 1: What is an algorithm?

An algorithm is a set of instructions or steps designed to solve a specific problem or perform a specific task. It is a series of well-defined, logical steps that can be followed to achieve a desired outcome.

Question 2: Why are algorithms important?

Algorithms are important because they allow us to solve complex problems efficiently and accurately. They are the foundation for many technological advancements and are used in various fields such as computer science, engineering, and data analysis.

Question 3: How do algorithms work?

Algorithms work by breaking down a problem into smaller, more manageable steps that can be repeated until the desired outcome is achieved. These steps are often written in a programming language and can include conditions, loops, and mathematical operations.

Question 4: What is the difference between a simple and a complex algorithm?

A simple algorithm is one that can be easily understood and executed by a human. It usually consists of a few basic steps and can be solved without the use of advanced techniques. On the other hand, a complex algorithm may involve more intricate steps and require specialized knowledge or tools to solve.

Question 5: How do algorithms impact our daily lives?

Algorithms have a significant impact on our daily lives, from the way we search for information on the internet to the way we navigate through traffic. They are used in various applications, such as social media, e-commerce, and navigation systems, to provide personalized recommendations and streamline processes.

Similar threads

Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
6K
  • Programming and Computer Science
Replies
7
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Back
Top