Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get how many days in current month

import calendar
import datetime
now = datetime.datetime.now()
print calendar.monthrange(now.year, now.month)[1]
29
Comment

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 :: where is python installed on ubuntu 
Python :: intellij python 
Python :: python initialize dict with empty list values 
Python :: vscode set python identation to four 
Python :: minmaxscaler python 
Python :: create a dataframe from dict 
Python :: how to pass parameters in python script 
Python :: how to download a .xlsx file from google colab 
Python :: python sort the values in a dictionaryi 
Python :: generate secret key python 
Python :: how to make python open a program/desktop app 
Python :: how to show a frequency distribution based on date in python 
Python :: button tkinter 
Python :: python find digits in string 
Python :: list exclude list 
Python :: how to convert dataframe to text 
Python :: django environment variables 
Python :: pandas convert numbers in parentheses to negative 
Python :: How to combine train and Test dataset in python 
Python :: python f string 2 decimals 
Python :: joins in pandas 
Python :: regex remove all html tags except br python 
Python :: str replace python regex 
Python :: Support Vector Machine (SVM) classifier 
Python :: python strip 
Python :: how to get last n elements of a list in python 
Python :: python numpy matrix to list 
Python :: python get current class name 
Python :: python tqdm 
Python :: import system in python 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =