HP Forums
HP Prime: Day Number of the Year - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: HP Prime: Day Number of the Year (/thread-485.html)



HP Prime: Day Number of the Year - Eddie W. Shore - 01-21-2014 01:24 PM

This formula calculates the day number of any date (given month and day). A 365 day year is used. If you are operating with a leap year with dates after February 28, add 1.

Hence in non-leap years, January 1 is Day 1, February 1 is Day 32, etc..., December 1 is 335, and December 31 is 365.

Details are at my blog: http://edspi31415.blogspot.com/2014/01/hp-prime-and-hp-32sii-day-number-of-year.html

Formula:

Day Number, 365 Day Year, M≤2:
D + IP(30.6M + 1.6 + 367.2) - (34 + 365) = D + IP(30.6M + 368.8) - 399

M>2:
D + IP(30.6M + 1.6) - 34

HP Prime Program DAYNO:
EXPORT DAYNO(M,D)
BEGIN
IF M≤2 THEN
RETURN IP(30.6*M+368.8)+D-399;
ELSE
RETURN IP(30.6*M+1.6)+D-34;
END;
END;


RE: HP Prime: Day Number of the Year - Damien - 01-21-2014 03:31 PM

Hi everyone,

For any gregorian date (year>1582). The Nth day of the year can be calculated with the formulas:

For non leap year:
N=INT(275*Month/9)-2*INT((Month+9)/12)+Day-30
For leap year:
N=INT(275*Month/9)-INT((Month+9)/12)+Day-30
With Month from 1 to 12, Day from 1 to 31.
(Taken from a book about astronomical calculation written by Jean MEEUS)

For the Prime something like that should work fine:
Code:

EXPORT Date2Days(date)
BEGIN
LOCAL b,a,m,j;
// date : [YYYY].[MM][DD]
 IP(date)▶a; // YYYY
 IP(FP(date)*100)▶m; // MM
 IP(FP(FP(date)*100)*100)▶j; // DD
// gregorian leap year ?
 IF (NOT(a MOD 4) AND a MOD 100)  
     OR (NOT (a MOD 400)) THEN 
  b:=1; // leap year 
 ELSE
  b:=2; //ordinary year
 END;
 RETURN IP(275*m/9)-b*IP((m+9)/12)+j-30;
END;

Enter dates in HP Prime format : YYYY.MMDD

Example: 1970 june 9th (1970.0609) gives N=160.

Regards,

Damien.