[Tutor] how to get the weeks of a month

Mark Lawrence breamoreboy at gmail.com
Mon Mar 4 14:12:23 EST 2019


On 04/03/2019 18:54, john fabiani wrote:
> Hi everyone,
> 
> I'm not exactly a newbie but I can't seem to solve this problem.
> 
> I need to print out the weeks of the month - given any month and any year.
> 
> For example this month would have:
> 
> 3/1/2019 - 3/3/2019   # notice that this a short week
> 3/4/2019 - 3/10/2019
> 3/11/2019 - 3/17/2019
> 3/18/2019 - 3/24/2019
> 3/25/2019 - 3/31/2019  # also this can be a short week as in April 2019 
> last week would be 4/29/2019 - 4/30-2019
> 
> I have tried using isocalendar, dateutil, and just plain datetime.
> 
> I get close but no real solution. Google wasn't much help either.  So I 
> thought I'd ask here - you have been helpful in the past.  And no at my 
> age I am not attending school - so this not my homework.
> 
> Johnf
> 

Have you tried any of monthdatescalendar, monthdays2calendar or 
monthdayscalendar from https://docs.python.org/3/library/calendar.html?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list