Apr-02-2023, 07:21 PM
(Apr-02-2023, 11:38 AM)deanhystad Wrote: This should divide by 12, not 4.
d = ((367 * (month-2-12*a)) / 4)The other differences are caused by Python doing floating point math and bash doing integer math. The first pass at fixing your equations I tried this:
a = ((month-14) // 12) b = ((year+4900+a) // 100) c = ((1461*(year+4800+a)) // 4) d = ((367 * (month-2-12*a)) // 12)This was a little off. a was -1 instead of 0. When doing integer division, // does floor division, not truncating. Use int() to truncate.
Second pass.
a = int((month-14) / 12) b = int((year+4900+a) / 100) c = int((1461*(year+4800+a)) / 4) d = int((367 * (month-2-12*a)) / 12)I see no reason for adding 1 to the day. This is my version of your converter. I hard coded date to match your example.
from datetime import datetime now = datetime.strptime("3 4 2023", "%d %m %Y") # Remove comment to convert current date # now = datetime.now() day = now.day month = now.month year = now.year print(day, month, year) a = int((month-14) / 12) b = int((year+4900+a) / 100) c = int((1461*(year+4800+a)) / 4) d = int((367 * (month-2-12*a)) / 12) print(a, b, c, d)
Output:3 4 2023 0 69 2492100 61
Ahh thank you. Didn't thought of that. But it worked :)