Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python first day of last month

from datetime import date, timedelta

last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)

start_day_of_prev_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)

# For printing results
print("First day of prev month:", start_day_of_prev_month)
print("Last day of prev month:", last_day_of_prev_month)
Comment

python datetime last day of month

>>import calendar
>>year, month = 2016, 12
>>calendar.monthrange(year, month)[1]
31
Comment

get last day of month python

import datetime
def last_day_of_month(any_day):
	# get close to the end of the month for any day, and add 4 days 'over'
	next_month = any_day.replace(day=28) + datetime.timedelta(days=4)
	# subtract the number of remaining 'overage' days to get last day of current month, or said programattically said, the previous day of the first of next month
	return next_month - datetime.timedelta(days=next_month.day)


last_date_of_month(datetime.date.today())
Comment

PREVIOUS NEXT
Code Example
Python :: python filter list of dictionaries by value 
Python :: popup window python tkinter 
Python :: AdaBoost in Python 
Python :: isinstance float or int 
Python :: python no such file python3 
Python :: flask db migrate 
Python :: how to make a latency command discord.py 
Python :: remove columns that contain certain names in pandas 
Python :: how to click on button using python 
Python :: python get day month year 
Python :: python tkinter askopenfile 
Python :: pandas remove item from dictionary 
Python :: python program to find factorial 
Python :: request.body django 
Python :: np.array average row 
Python :: python close browser 
Python :: python string to hex 
Python :: numpy check if 2 array identical 
Python :: pd dataframe get column names 
Python :: sys.executable 
Python :: django create token for user 
Python :: tofixed in python 
Python :: python from timestamp to string 
Python :: python count total no of word in a text 
Python :: change python version ubuntu 
Python :: replace nat with date pandas 
Python :: how to check if file exists pyuthon 
Python :: time until 2021 
Python :: python multiply list 
Python :: python merge list into string 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =