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 :: matplotlib transparent line 
Python :: how to save array python 
Python :: pyautogui pause in python 
Python :: django admin image 
Python :: main arguments python 
Python :: python remove duplicates from a list 
Python :: python square root 
Python :: forbidden (csrf cookie not set.) django rest framework 
Python :: Finding the Variance and Standard Deviation of a list of numbers in Python 
Python :: python dataframe column string to integer python 
Python :: how to import random module in python 
Python :: django sort queryset 
Python :: pillow create image 
Python :: logging the terminal output to a file 
Python :: Parameter Grid python 
Python :: shift coordinate in python 
Python :: convert excel to csv using python 
Python :: python get files in directory 
Python :: creata daframe python 
Python :: python find location of module 
Python :: python virus 
Python :: python iterate over multidimensional dictionary 
Python :: indices of true boolean array pyton 
Python :: selenium scroll down python 
Python :: https flask 
Python :: how to write a numpy array to a file in python 
Python :: how to sort a list in python using lambda 
Python :: django.core.exceptions.ImproperlyConfigured 
Python :: distribution seaborn 
Python :: how to input 2-d array in python 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =