Sunday, January 13, 2019

HP Prime, TI-84 Plus, and Casio fx-CG 50: Julian Date/Gregorian Calendar Conversions

HP Prime, TI-84 Plus, and Casio fx-CG 50:  Julian Date/Gregorian Calendar Conversions

Introduction

One conversion that is common in astronomy is to convert dates from our Gregorian calendar (the most commonly used day-to-day calendar) to a Julian Date Number, and visa versa.

JD:  Convert Gregorian Date to Julian Date Number

GREG:  Convert Julian Date Number to Gregorian Date

The Julian date number of 2451545 corresponds to January 1, 2000.

Gregorian Date to Julian Date Number

HP Prime Program JD:  Gregorian Date to Julian Date Number
Arguments:  four digit year, month, day
JD(y,m,d)

EXPORT JD(y,m,d)
BEGIN
// Gregorian to Julian
// year, month, day
// 2019-01-12 EWS
//  Wikipedia
LOCAL x0:=IP((m-14)/12);
LOCAL x1:=IP(((1461*(y+4800+x0))/4));
LOCAL x3:=IP(367*(m-2-12*x0)/12);
LOCAL x5:=IP((y+4900+x0)/100);
LOCAL x6:=IP(3*x5/4);
LOCAL j:=x1+x3-x6+d-32075;
RETURN j;
END;

TI-84 Plus Program JD:  Gregorian Date to Julian Date Number

"GREGORIAN TO JULIAN"
"2019-01-13 EWS"
Input "YEAR: ",Y
Input "MONTH: ",M
Input "DAY: ",D
iPart((M-14)/12)→X
iPart(((1461*(Y+4800+X))/4))→A
iPart(367*(M-2-12*X)/12)→B
iPart((Y+4900+X)/100)→C
iPart(3*C/4)→C
A+B-C+D-32075→J
Disp "JD: ",J

Casio fx-CG50 Program JD:  Gregorian Date to Julian Date Number
This version can be typed in directly in the calculator (not a text file)

"GREGORIAN TO JULIAN"
"2019-01-19 EWS"
"YEAR?"→Y
"MONTH"?→M
"DAY"?→D
Int ((M-14)÷12)→X
Int (((1461×(Y+4800+X))÷4)) →A
Int (367×(M-2-12×X)÷12) →B
Int ((Y+4900+X) ÷ 100) →C
Int (3×C÷4)→C
A+B-C+D-32075→J
ClrText
Locate 1,1,"JD"
Locate 1,2,J

Julian Date Number to Gregorian Date

HP Prime Program GREG:  Julian Date Number to Gregorian Date
Argument:  Julian Date Number
GREG(j)

EXPORT GREG(j)
BEGIN
// Julian to Gregorian
// Wikipedia
// 2019-01-12 EWS
LOCAL x1:=IP((4*j+274277)/146097);
LOCAL x2:=IP(x1*3/4);
LOCAL f:=j+1401+x2-38;
LOCAL E:=4*f+3;
LOCAL G:=IP((E MOD 1461)/4);
LOCAL H:=5*G+2;
LOCAL D:=IP((H MOD 153)/5)+1;
LOCAL M:=((IP(H/153)+2) MOD 12)+1;
LOCAL Y:=IP(E/1461)-4716+IP((12+2-M)/12);
RETURN {Y,M,D};
END;

TI-84 Plus Program GREG:  Julian Date Number to Gregorian Date

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
Input "JD: ",J
iPart((4*J+274277)/146097)→X
iPart(X*3/4)→X
4*(J+1401+X-38)+3→E
5*iPart(remainder(E,1461)/4)+2→H
iPart(remainder(H,153)/5)+1→D
remainder(iPart(H/153)+2,12)+1→M
iPart(E/1461)-4716+iPart((12+2-M)/12)→Y
Disp "YEAR, MONTH, DAY:",Y,M,D

Casio fx-CG50 Program GREG: Julian Date Number to Gregorian Date 
This version can be typed in directly in the calculator (not a text file)

"JULIAN TO GREGORIAN"
"2019-01-13 EWS"
"JD"?→J
Int ((4 ×J+274277) ÷146097) →X
Int (X ×3 ÷4) →X
4 ×(J+1401+X-38)+3 → E
5 × Int( MOD(E,1461) ÷ 4)+2 → H
MOD(Int  (H ÷153)+2,12)+1 →M
Int (E ÷1461) -4716+Int ((12+2-M) ÷12) → Y
ClrText
Locate 1,1,"YEAR, MONTH, DAY"
Locate 1,2,Y
Locate 1,3,M
Locate 1,4,D

Examples

Gregorian Date:  1988, October 31
JD:  2447466

Gregorian Date:  1999, January 11
JD:  2451190

Gregorian Date:  2017, March 21
JD:  2457834


Source:

"Julian Day"  Wikipedia.  Edited (when retrieved) November 19, 2018.  Retrieved January 11, 2019.  https://en.wikipedia.org/wiki/Julian_day

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

TI 30Xa Algorithm: Acceleration, Velocity, Speed

TI 30Xa Algorithm: Acceleration, Velocity, Speed Introduction and Algorithm Given the acceleration (α), initial velocity (v0), and...