Monthly Archives: April 2014

Python: find all the dates of a given week day in a given range

FacebookTwitterGoogle+LinkedIn

Recently I had a requirement to get all the dates of  Saturdays and Sundays in a particular year. I wrote a more generic function to implement the same. This function accepts start date and end dates and finds all the dates for a given list of week days in day_list parameter. Week day number starts with Monday being 0 (zero) to 6 (Sunday). So, If you have to find all the Mondays in the year, pass [0] in the day_list parameter. from_date and end_date are python date objects.

 

Here day_list is the week number list, for which dates are to be found and from_date and to_date make a date range where these dates have to be scanned in.

FacebookTwitterGoogle+LinkedIn