Simpler Datenum
#4
It seems like it was just a few days ago that I posted about this
https://staging.qb64phoenix.com/showthread.php?tid=65

So I changed it to take into account leap-years.  Very interesting.
The big "Int" statement starts the year with March, and Jan & Feb get moved to 13 and 14. Then the MOD 365 brings them back.
This code has just numerics; no strings.  Great fun.  Thanks.

Code: (Select All)
Print "m d", 2022, 2024, 2100, 2400
For m = 1 To 12
  Print m; 1, func(m, 1, 2022), func(m, 1, 2024), func(m, 1, 2100), func(m, 1, 2400)
Next m
Print 12; 31, func(12, 31, 2022), func(12, 31, 2024), func(12, 31, 2100), func(12, 31, 2400)

Function func (m, d, y)
  ret = d + Int((295 + 153 * ((m + 9) Mod 12) + 2) / 5) Mod 365
  If y Mod 4 = 0 And (y Mod 100 <> 0 Or y Mod 400 = 0) And m > 2 Then ret = ret + 1
  func = ret
End Function
Reply


Messages In This Thread
Simpler Datenum - by doppler - 05-04-2022, 04:43 PM
RE: Simpler Datenum - by Pete - 05-04-2022, 05:38 PM
RE: Simpler Datenum - by Pete - 05-04-2022, 07:10 PM
RE: Simpler Datenum - by dcromley - 05-05-2022, 04:49 AM
RE: Simpler Datenum - by Pete - 05-05-2022, 05:35 AM
RE: Simpler Datenum - by doppler - 05-05-2022, 02:10 PM
RE: Simpler Datenum - by Pete - 05-05-2022, 02:22 PM
RE: Simpler Datenum - by euklides - 05-07-2022, 07:59 AM
RE: Simpler Datenum - by doppler - 05-07-2022, 01:27 PM
RE: Simpler Datenum - by euklides - 05-08-2022, 11:59 AM



Users browsing this thread: 4 Guest(s)