Skip to content

Instantly share code, notes, and snippets.

@Godwhitelight
Created April 19, 2023 20:28
Show Gist options
  • Save Godwhitelight/1c6ea9c230b4633d72476b7befd96f0f to your computer and use it in GitHub Desktop.
Save Godwhitelight/1c6ea9c230b4633d72476b7befd96f0f to your computer and use it in GitHub Desktop.
get days in a month in a year python
def get_days(month: int, year: int):
"""
Get the number of days in a month
:param month: The month
:param year: The year
:return: The number of days in the month
:Example:
>>> get_days(2, 2020)
29
>>> get_days(2, 2019)
28
>>> get_days(4, 2020)
30
"""
if month == 2:
if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
return 29
return 28
return 30 + (1 - (month % 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment