Software engineering and personal development

Tag: days

How to Get the Number of Days in a Month in Python

If you need to get the number of days in a month in Python, you can do that quite quickly.

We are going to do that using the calendar module.

First, import the calendar module and then call the method monthrange() which returns the first_day and also the number_of_days in a month.

Let us see this in action:

 import calendar
 ​
 # Get current month
 _, number_of_days = calendar.monthrange(2023, 2)
 ​
 print(number_of_days)  # 28
Continue reading

How To Quickly Find The Number Of Days Between 2 Dates In Python

laptop on brown sofa
Photo by XPS on Unsplash

If you use Python in your work, or simply for scripting, chances are that there will come a point in time when you are going to need to work with dates.

Since we still live in this universe where time passes, we may need to find the number of days that have passed between one point and another one.

We can of course pull up a calendar and manually count the days, which is slow and boring.

Continue reading

© 2024 Fatos Morina

Theme by Anders NorenUp ↑