'How do I get number of days in a month in python? [duplicate]
So I have a school project and I need help with a part of my code. I need to be able to subtract the number that has been inputed with the number of days in a specific month but I am unsure of how to do so. Here is the part of my code:
days = int(birthdayd) - int(todayd)
while days < 0:
day2 = day + ***days in month***
else:
pass
Solution 1:[1]
The function monthrange() can give the the number of days in the month, but you need to know the month and the year.
from calendar import monthrange
yr = 2022
mt = 3
num_days = monthrange(yr, mt)[1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
