Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

number of days in a month python

>>> from datetime import date
>>> (date(2012, 3, 1) - date(2012, 2, 1)).days
29
Comment

number of days in a month python

(dt.replace(month = dt.month % 12 +1, day = 1)-timedelta(days=1)).day
Comment

number of days in a month python

>>> from calendar import monthrange
>>> monthrange(2011, 2)
(1, 28)
Comment

days in month function python

def leap_year(year):
    if year % 400 == 0:
        return True
    if year % 100 == 0:
        return False
    if year % 4 == 0:
        return True
    return False

def days_in_month(month, year):
    if month in {1, 3, 5, 7, 8, 10, 12}:
        return 31
    if month == 2:
        if leap_year(year):
            return 29
        return 28
    return 30

print(days_in_month(2, 2016))  # 29
Comment

return days of month python

>>> from calendar import monthrange
>>> monthrange(2012, 2)
(2, 29)
# First number is the weekday of the first day of the month, 
# the second number is the number of days in said month
Comment

PREVIOUS NEXT
Code Example
Python :: convert negative to positive in python 
Python :: how to install arcade in python 
Python :: wikipedia python module 
Python :: convert a text file data to dataframe in python without pandas 
Python :: Merge two data frames based on common column values in Pandas 
Python :: list of dicts 
Python :: cv2 imwrite 
Python :: how to print all items in a list python 
Python :: tkinter toplevel 
Python :: days to int 
Python :: remove brases from array py 
Python :: access class variable from another class python 
Python :: python add attribute to class instance 
Python :: Django how to get url path for a view 
Python :: python primes 
Python :: how to declare np datetime 
Python :: is python object oriented language 
Python :: python new date 
Python :: record audio with processing python 
Python :: break while loop python 
Python :: enable time layer arcpy 
Python :: how to get wikipedia photos using wikipedia module ip python 
Python :: load python file in jupyter notebook 
Python :: python requests no certificate example 
Python :: how to host python flask web application 
Python :: random.uniform python 
Python :: change password django 
Python :: text animation python 
Python :: best fit line python log log scale 
Python :: keras model compile 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =