Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python create time slot within duration

import datetime as dt

class TimeSlots():

  @staticmethod
  def time_slots(start, end):
    start_time = dt.datetime.strptime(start, '%H:%M:%S')
    end_time = dt.datetime.strptime(end, '%H:%M:%S')
    time_interval = dt.datetime.strptime('00:15:00', '%H:%M:%S')
    time_zero = dt.datetime.strptime('00:00:00', '%H:%M:%S')
    timeslots = []
    while end_time > start_time:
      end = ((start_time - time_zero + time_interval))
      timeslot = f'{(start_time).time() } - {(end).time()}'
      # print(timeslot)
      timeslots.append(timeslot)
      start_time = end
    return timeslots

print(TimeSlots.time_slots("15:00:00", "18:00:00"))
 
PREVIOUS NEXT
Tagged: #Python #create #time #slot #duration
ADD COMMENT
Topic
Name
3+1 =