Number of Days After January 1

03112019, 02:25 AM
Post: #1




Number of Days After January 1
Introduction
The program DATENO calculates the number of days from January 1. The program prompts whether we are working in a leap year or not. With D = Day and M = Month, the days between January 1 and any other date within the calendar year is: If M = 1 and M = 2 Then DATE# = int(30.6 * M + 368.8) + D  400 Otherwise, DATE# = int(30.6 * M + 1.6) +D  35 (nonleap year) DATE# = int(30.6 * M + 1.6) + D  34 (leap year) HP 41C/DM 41L Program: DATENO (^T: beginning of an alpha string) Code: 01 LBL^T DATENO Examples Days between January 1 and February 16 (M = 2, D = 16): 46 Days between January 1 and October 1 (M = 10, D = 1): (Nonleap year): 273 (Leap year): 274 Link to blog post: https://edspi31415.blogspot.com/2019/03/...days.html 

03112019, 06:53 PM
(This post was last modified: 03112019 07:00 PM by Dieter.)
Post: #2




RE: Number of Days After January 1
(03112019 02:25 AM)Eddie W. Shore Wrote: The program DATENO calculates the number of days from January 1. Maybe you should add 1 to the result to get the more common "day of year", i.e. 1 January = day 1 and 31 December = day 365. (03112019 02:25 AM)Eddie W. Shore Wrote: If M = 1 and M = 2 Then What about 31*M + D 32 ?) Anyway, here is my attempt at a dayofyear program. I have derived the formulas myself, so beware. ;) Please try it and report any errors you find. Code: 01 LBL "DOY" Usage: day [ENTER] month [ENTER] year XEQ "DOY" If you prefer month, day, year instead simply insert an X<>Y command between line 08 and 09. The program automatically checks for leap years, this works for all dates between 1 January 1901 and 28 February 2100. Example: 1 [ENTER] 10 [ENTER] 1999 XEQ"DOY" => 274 1 [ENTER] 10 [ENTER] 2000 XEQ"DOY" => 275 Dieter 

03112019, 08:30 PM
Post: #3




Number of Days After March 1st
(03112019 02:25 AM)Eddie W. Shore Wrote: The program DATENO calculates the number of days from January 1. Somewhat related is the following program from the article Sunrise and Sunset. Here it is adapted for the HP42S: Code: 00 { 30Byte Prgm } Examples: 1.03 R/S 1 28.02 R/S 365 29.02 R/S 366 This avoids having to deal with leap years. Cheers Thomas 

03142019, 07:20 PM
Post: #4




RE: Number of Days After January 1
(03112019 02:25 AM)Eddie W. Shore Wrote: If M = 1 and M = 2 Then Eddie, you can simplify these formulas significantly. Since D and 400 are positive integers... int(30.6 * M + 368.8) + D  400 = int(30.6 * M + 368.8 + D  400) = int(30.6 * M + D  31.2) Or here (D=1 or 2) simply = int(30.6 * M + D  31) The two other formulas can be simplified the same way. Or they can be derived from the Jan/Feb formula. With L=0 (common year) or 1 (leap year): days = 30.6 * M + D  31 if M >= 3 then days = days  2.3 + L return int(days) Note: according to your formulas the final 2.3 would be 2.4, but subtracting only 2.3 leaves a fractional part between 0.1 and 0.9 so that roundoff problems are avoided (e.g. in nondecimal environments) that may lead to cases like int(242.9999999....) for 1 September. Here is a version of your HP41C program that implements this idea. Code: 01 LBL "DAYD" XEQ "DAYD" MONTH↑DAY ? 10 [ENTER] 1 [R/S] LEAP YR 0/1? 0 [R/S] => 273 Note that the program only prompts for a leap year input if this is required, i.e. for months between March and December. Dieter 

« Next Oldest  Next Newest »

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