Wednesday, 11 May 2016

How to find last day of current month and first day of current month in Python ?

For finding last day of current month, we need to use calendar and datetime python libraries.

Following is an example of it.

>>> import calendar
>>> import datetime

>>> calendar.mdays[datetime.date.today().month]
31

>>> datetime.datetime.today().replace(day=1)
It will replace today's date with starting date of month.

I hope you like this article. Share your views to improve content. Happy Learning !!!

No comments:

Post a Comment

ImportError: cannot import name 'utils' from 'PyPDF2'

Odoo 15: Traceback (most recent call last):   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner     self...