Datetime module in Python (inspired by Basta Fazoolin')

Hi all,

I met an interesting issue yesterday with the Basta Fazoolin’ exercise when it asked “create an available_menus() method that takes in a time parameter and returns a list of the Menu objects that are available at that time.”

The obvious issue is at this point in the cs path, time and datetime modules aren’t mentioned. So the only tools to compare hours would be to parse strings (like 11AM) and give them a 24 hr format with conditionals. Which all felt a little inefficient and roundabout.

I found that to be a great opportunity to look into better ways to approach this function, but surprisingly there is very little entry level material for the datetime module (I searched for quite a bit on google, and have the big O’Reilly book). The official Python documentation is indeed informative, but it can be daunting and for a specific need wasn’t giving me what I needed.

However I did come across a thorough video that set up a lot of good principal ideas, and from there it was easy to devise how I could finally write the function I wanted. Here’s the link if you’re interested (

I hope this gives some ideas to fellow learners, and if CA people see this, intro courses (or links) into handling time could be nice touch in the future :slight_smile:


There’s defintiely a short CA video on the datetime module but that might be under learn python rather than the compsci course, I couldn’t say for certain. A helpful resource is a helpful resource though, ta.

I went the opposite route for this task and rather enjoyed sorting that out as a small class or callable function and you can make sure there’s no misinterpretation of 12 am/pm, since this can vary, with noon and midnight instead. Made a nice additional step. Worth learning your way around the datetime module though for sure.

1 Like

@tgrtim Ah interesting. I was just thinking it’d be nice if they had a tab of indices on the side of subject topics for quicker reference.