(12C) Gregorian Date to Julian Day Number and vice versa

01142019, 12:54 PM
(This post was last modified: 01142019 02:45 PM by Dieter.)
Post: #1




(12C) Gregorian Date to Julian Day Number and vice versa
The Julian Day number (JDN) of a date in the Gregorian calendar can be easily calculated with the 12C's builtin date functions. These also allow to convert a JDN back to a Gregorian date. Since that calendar started on 15 October 1582, this is the earliest possible date. The 12C will return an error for earlier dates.
The following program automatically chooses the appropriate conversion: if the input is an integer it cannot be a date so it has to be a JDN which is then converted into a date. If the input has a fractional part it is considered a date which is converted to the corresponding JDN. The program works independent of the date format setting, both D.MY and M.DY are fine. This is achieved by selecting 1 Jan 2000 as a reference date which is entered/displayed as 1,012000 in either date mode. Its corresponding JDN is 2451545. To convert a date to its JDN the program determines the number of days since 1 Jan 2000 (this may be positive or negative) and then adds 2451545 to the result. To convert a JDN back to the corresponding date, 2451545 is subtracted (giving the number of days before/after 1 Jan 2000) and then the latter date is added. Code: 01 FRAC Example (assuming D.MY mode): 4,071979 [R/S] => 2444059 2444444 [R/S] => 23,071980 If the real 12C hehaves like HP's emulator you should even see "23.07.1980 3" for a moment, indicating the day of week (Wednesday). Dieter 

01142019, 03:50 PM
(This post was last modified: 01142019 11:28 PM by Albert Chan.)
Post: #2




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 12:54 PM)Dieter Wrote: Example (assuming D.MY mode): Perhaps calculation via Modified Julian Date Number is easier: https://www.hermetic.ch/cal_stud/jdn.htm MJD = JD  2,400,000.5 = (JD0.5)  24e5 Store date, Nov 16, 1858, to memory 0 Redo above examples: RCL 0 4.071979 ΔDYS ==> 44059 RCL 0 44444 DATE ==> 23,07,1980 3 Edit: stored date were off by 1, to compensate for roundedup JD Officially, MJD(Nov 17, 1858, 00:00:00) = 0 17.111858 Enter 4.071979 ΔDYS => 44058 MJD => 2444058.5 JD, roundedup to 2444059 

01142019, 04:58 PM
(This post was last modified: 01142019 05:09 PM by Dieter.)
Post: #3




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 03:50 PM)Albert Chan Wrote: Perhaps calculation via Modified Julian Date Number is easier: It's not easier, as it's essentially the same calculation. And since 16,111858 ≠ 11,161858 it does not work for both date modes. But there is one advantage: you can quickly do the calculation manually, once the base date has been stored somewhere, as shown in your examples. BTW, please let's be precise here and distinguish between Julian dates (JD) and Julian day numbers (JDN). (01142019 03:50 PM)Albert Chan Wrote: https://www.hermetic.ch/cal_stud/jdn.htm Yes, there are lots of such variations, cf. https://en.wikipedia.org/wiki/Julian_day#Variants. But the program is supposed to calculate the original JDN, not a modified variant. Since for the 12C the hardware limitations that led to most of such modifications do not apply I don't think that these make much sense. Dieter 

01142019, 05:30 PM
(This post was last modified: 01142019 06:37 PM by Albert Chan.)
Post: #4




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 04:58 PM)Dieter Wrote: BTW, please let's be precise here and distinguish between Julian dates (JD) and Julian day numbers (JDN). I was using the abbreviation from https://www.hermetic.ch/cal_stud/jdn.htm, section 6: "Given a Julian day number JD, the modified Julian day number MJD is defined as MJD = JD  2,400,000.5" But, now that you mentioned it ... what is the difference ? 

01142019, 05:52 PM
(This post was last modified: 01142019 06:31 PM by Dieter.)
Post: #5




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 05:30 PM)Albert Chan Wrote: I was using the abbreviation from https://www.hermetic.ch/cal_stud/jdn.htm, section 6: My understanding is that Julian dates may include the time as fractional part, i.e. JD 2444059 is 4 Jul 1979 at noon and 2444059,6 is 5 Jul 1979 at 2:24 h. One the other hand the Julian day number (sic!) is an integer indicating the ordinal number of that day (from 0:00 to 23:59'59,999...."), starting at a certain point in the past (here 1 Jan 4713 BC). This causes an offset of 0,5 between both definitions, apart from the one being a real number and the other an integer. Please correct me if I'm wrong here. Addendum: The German Wikipedia article on Julian Dates includes two good and concise commented algorithms for the conversion between dates in the Julian and Gregorian calendar and the Julian date / day number. There also is a detailled and comprehensive explanation how the formula works. So at least if you read German you should take a look at that. Dieter 

01142019, 06:27 PM
(This post was last modified: 01142019 06:50 PM by Albert Chan.)
Post: #6




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 05:52 PM)Dieter Wrote: My understanding is that Julian dates may include the time as fractional part ... I thought so too, until I tried Julian Day Number Calculator. For Jan 1, 2000, it calculated a Julian Day Number of 2451544.5 

01142019, 09:28 PM
Post: #7




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 06:27 PM)Albert Chan Wrote: I thought so too, until I tried Julian Day Number Calculator. From the sources: Code: <! This is what an HTML comment looks like (This line terminates HTML comment) > Good to know. This gave me a chuckle. And the fact that the page was was last modified on 980126. Will we eventually find a Y2K bug? The algorithm is described on a related page: Quote:It is easy (with your calculator) to calculate the Julian Day Number of any date given on the Gregorian Calendar. The Julian Day Number so calculated will be for 0 hours, GMT, on that date. Here's how to do it: But this appears to be what's calculated in the JavaScript sources: Code: if(M<3) { Which appears to be consistent with Dieter's link to Wikipedia: Quote:wenn Monat > 2 dann Y = Jahr, M = MonatExcept that the variable H for hours is missing. And that's what I got for 20000101 using Python: Code: >>> Y, M, D = 2000  1, 1 + 12, 1 But I have to admit that I still don't really understand the difference between Julian Date and Julian Day Number. Cheers Thomas 

01152019, 12:43 PM
(This post was last modified: 01152019 01:14 PM by Albert Chan.)
Post: #8




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01142019 09:28 PM)Thomas Klemm Wrote: But I have to admit that I still don't really understand the difference between Julian Date and Julian Day Number. Based on Astronomy Answers: Julian Day Number Chronological Julian Date assumed timer started at 00:00:00 LT, instead of 12:00:00 UTC For Jan 1, 2000, 00:00:00 UTC, time zone TZ = +6 hrs = 0.25 day JDN = floor(JD) = floor(2451544.5) = 2451544 CJDN = floor(CJD) = floor(JD + TZ + 0.5) = 2451545 If true, what post #1 calculated is actually Chronological Julian Day Number. 

01162019, 05:13 PM
Post: #9




RE: (12C) Gregorian Date to Julian Day Number and vice versa
From HP12C owner's manual, valid date range = Oct 15, 1582 to Nov 25, 4046
It is trivial to extend the range, using the fact Gregorian calendar cycle of 400 years. Average days per year = (400*365 + 97 leap years)/400= 146097/400 = 365.2425 Example: CJDN(Dec 31, 9999) = CJDN(Dec 31, 1999) + 8000 years = (24515451) + 8000 * 365.2425 = 5373484 Since 146097 % 7 = 0, weekday(Dec 31, 9999) = weekday(Dec 31, 1999) = Friday 

01162019, 05:42 PM
(This post was last modified: 01162019 05:43 PM by Dieter.)
Post: #10




RE: (12C) Gregorian Date to Julian Day Number and vice versa
(01162019 05:13 PM)Albert Chan Wrote: From HP12C owner's manual, valid date range = Oct 15, 1582 to Nov 25, 4046 I wonder why the date range is limited to this 900.000 day period at all. The usual formula does not cause such limitations. (01162019 05:13 PM)Albert Chan Wrote: CJDN(Dec 31, 9999) This is also the result with "the usual formula". The WP34s, for instance, handles this easily. (01162019 05:13 PM)Albert Chan Wrote: Since 146097 % 7 = 0 I assume you mean 146097 mod 7 here.#) But then... who cares about dates in 4000 or 8000 years? The Julian calendar was in use for about 1600 years (but it still is, here and there), and the current Gregorian system is not moch more than 400 years old. So who knows what calendar will be in use several thousand years from now? Dieter 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)