How do I know how many days are between dates without using the datetime function?
For example, from October 20, 1950 to December 17, 2020, How do I calculate the number of days?
python
Calculate the number of dates from January 1, 1950 to October 20, 1950, and store them in a After calculating the number of dates from January 1, 1950 to December 17, 2020, and storing them in b, Please say b-a.
Time libraries are implemented in this way. We usually calculate based on January 1, 1970.
When calculating a or b, notice that in leap years, one year is 366 days, and in leap years, February is 29 days. Just keep this in mind and turn the repetition, and Yeon-yeon adds 365 or 366 while checking if it's a leap year, and if it's a leap year, you add the number of days per month, noting that February is the 29th.
Typically, the data types in libraries that use dates store the number of dates as of January 1, 1970. For example, January 1, 1970 stores zero, January 2, 1970 stores one. Eventually, the difference between the two dates is 1-0.
© 2024 OneMinuteCode. All rights reserved.