Quantcast
Channel: Parsing day/time format - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Parsing day/time format

$
0
0

Having some trouble working with time in python. I'm trying to parse a maintenance window string and work out if we're in a maintenance window. So far I have the below but doesn't seem to work.

#!/usr/bin/pythonfrom datetime import datetimeimport reimport timemaintenance="sat:02:00-sun:03:00"# Split start time and end timemain_start, main_end = re.split(r"-", maintenance)main_start = datetime.strptime(main_start, "%a:%H:%M")main_end = datetime.strptime(main_end, "%a:%H:%M")now = datetime.now()if now >= main_start and now <= main_end:    print 'In maintenance window'

I think the problem is that I'm only wanting to concentrate on the day of week and time but its taking into account the year and month.

Struggling to work out how to achieve this.

I also didn't know if datetime would be able to take the input day of week (%a) as all lowercase.

Any help would be appreciated :)


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images