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

first day of the month python

from datetime import datetime

datetime.today().replace(day=1)
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 :: openpyxl font 
Python :: pandas datetime show only date 
Python :: pip version 
Python :: python random.choices vs random.sample 
Python :: seaborn create a correlation matrix 
Python :: pandas datetime now 
Python :: making spark session 
Python :: proxy selenium python 
Python :: droaw heat map in python for null values 
Python :: linear search in python 
Python :: python alfabet 
Python :: python get index of item in 2d list 
Python :: pandas groupby as new column 
Python :: insert picture into jupyter notebook 
Python :: python extract specific columns from pandas dataframe 
Python :: how to edit a specific line in text file in python 
Python :: plt off axis 
Python :: python datetime yesterday 
Python :: types of all columns pandas 
Python :: godot code for movement for topdown game 
Python :: seaborn increace figure size 
Python :: python play mp3 in background 
Python :: save dataframe to csv without index 
Python :: python sys halt 
Python :: change the default python version mac 
Python :: python string list to float 
Python :: python generate random strong password 
Python :: sigmoid function numpy 
Python :: python index of max value in list 
Python :: remove all files in a directory mac 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =