Skip to content
Advertisement

Get last friday of each month in python

I want last friday of each month for upcoming three months.

JavaScript

This gives me the nearest friday. I want to make sure this is the last friday of this month so that i can add 28 days to get next friday.

Advertisement

Answer

The easiest way to do this is to use the module dateutil:

JavaScript

Don’t assume you can get the last Friday of subsequent months just by adding 28 days. It won’t always work. Adding 28 days to the last Friday of February 2024 gives you this:

JavaScript

but the last Friday of that month is 29 March. Let dateutil do that correctly for you:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement