0

I have 2 datasets as follows:

dataset1 = [['05/06/2017 12:05:27', data1, data1],
            ['12/05/2017 12:30:27', data1, data1],
            .... .... 
           ]


dataset2 = [['06/02/2017 13:39:11', data2, data2],
            ['10/10/2016 11:26:40', data2, data2],
            .... ....
           ]

I am trying to create a condition where if the datetime in dataset1 is within 6 hours of the datetime in dataset2, add the data in dataset1 to the corresponding row in dataset2.

I have converted the datetime elements from str to datetime objects. And I think I need to use the timedelta function to see if the difference between the dates is less than 6 hours but the lists are not of equal size nor are the dates necessarily sequential so I'm not sure how to go about comparing the lists and finding a match.

What I've done so far is separate the datetime elements into new lists... pseudocode:

DatetimeDataset1 = [...]
DatetimeDataset2 = [...]

for i in DatetimeDataset1:
    for j in DatetimeDataset2:
         if i - j < 6 hours:
              do something!

How do I specify 6 hours in this condition in a way the objects would understand?

Need some direction.

Thanks

arsenal88
  • 1,040
  • 2
  • 15
  • 32
  • 2
    show us more of what you have done/tried – depperm Jun 15 '17 at 12:33
  • Get the right string, convert it to a datetime, and use datetime.timedelta for the 6 hours. – Kenny Ostrom Jun 15 '17 at 12:56
  • 1
    Possible duplicate of [How to calculate the time interval between two time strings](https://stackoverflow.com/questions/3096953/how-to-calculate-the-time-interval-between-two-time-strings) – jlange Jun 15 '17 at 13:05

0 Answers0