0

I am trying to convert the time(2018-08-03 11:30:00) in the datetime format(year, month, day, hour, min, sec) from a list in python. Can anyone help? Thank you so much for your time.

This is the preset code.

from datetime import datetime
class Meeting:
    def __init__(self, start_time, end_time):
        self.start_time = start_time
        self.end_time = end_time

My code:

for meeting in meetings:
    time1 = meeting.start_time 
    time2 = meeting.end_time 
    time3 = proposed_time      
    if time1 < time3 < time2:
        return False

    else:
        return True 

Here are the values that can be passed through my code.

meetings = [Meeting(datetime(2018, 8, 1, 9, 0, 0), datetime(2018, 8, 1, 11, 0, 0))    

Here are some values that CANNOT work for my code. So, I would like to convert for my code.

meetings = [Meeting(2018-08-03 11:30:00, 2018-08-03 13:15:00), Meeting(2018-08-07 15:15:00, 2018-08-07 16:45:00)] 
crazyGamer
  • 1,119
  • 9
  • 16
April
  • 13
  • 1
  • 1
  • 4
  • 3
    Possible duplicate of [Converting string into datetime](https://stackoverflow.com/questions/466345/converting-string-into-datetime) – glibdud Jan 28 '19 at 14:34
  • I didn't quite understand what do you want to do.. Do you want for this ```meetings = [Meeting(2018-08-03 11:30:00, 2018-08-03 13:15:00), Meeting(2018-08-07 15:15:00, 2018-08-07 16:45:00)] ``` to work? – akhavro Jan 28 '19 at 14:59
  • Yes, this is one of the values that need to be tested with my code. I was wondering how I can extract the time (2018-08-03 11:30:00) from the meetings list to set as time1. – April Jan 28 '19 at 16:03

2 Answers2

0

You can use the strptime for conversion. datetime.strptime('2018-08-03 11:30:00', '%Y-%m-%d %I:%M:%S')

Nithin
  • 153
  • 3
  • 6
  • I know that I can use strptime; however, I have to put value individually as the date_string. So I was wondering how I can extract the time from the meetings list. – April Jan 28 '19 at 14:50
0

Finally, I was able to extract the time from the meetings list by making the time1, time2, and time3 as strings. Thanks for the inputs!

April
  • 13
  • 1
  • 1
  • 4