(12C) Gregorian Date to Julian Day Number and vice versa
01-14-2019, 12:54 PM (This post was last modified: 01-14-2019 02:45 PM by Dieter.)
Post: #1
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
(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 built-in 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 02 x=0? 03 GTO 20 04 1 05 , 06 0 07 1 08 2 09 LstX 10 ΔDYS 11 2 12 4 13 5 14 1 15 5 16 4 17 5 18 + 19 GTO 00 20 LstX 21 2 22 4 23 5 24 1 25 5 26 4 27 5 28 - 29 1 30 , 31 0 32 1 33 2 34 X<>Y 35 DATE 36 GTO 00

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
 « Next Oldest | Next Newest »

 Messages In This Thread (12C) Gregorian Date to Julian Day Number and vice versa - Dieter - 01-14-2019 12:54 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Albert Chan - 01-14-2019, 03:50 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Dieter - 01-14-2019, 04:58 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Albert Chan - 01-14-2019, 05:30 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Dieter - 01-14-2019, 05:52 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Albert Chan - 01-14-2019, 06:27 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Thomas Klemm - 01-14-2019, 09:28 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Albert Chan - 01-15-2019, 12:43 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Albert Chan - 01-16-2019, 05:13 PM RE: (12C) Gregorian Date to Julian Day Number and vice versa - Dieter - 01-16-2019, 05:42 PM

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