Search
 
SCRIPT & CODE EXAMPLE
 

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"))
Comment

PREVIOUS NEXT
Code Example
Python :: what is self in python constructor 
Python :: python count down advanced 
Python :: python iterate through lists 
Python :: python find occurance of item 
Python :: python Access both key and value using items() 
Python :: Source code: Matrix Addition using Nested Loop 
Python :: geodataframe and geoseries 
Python :: remove from list python by index 
Python :: python sort_values 
Python :: how to read file again in python 
Python :: how to delete lists after using them in python 
Python :: how to preserve white space when joining an array python 
Python :: isat in panadas datframe 
Python :: oauthlib python error 
Python :: when excel is loaded into python, numeric datatype changes to float 
Python :: how to find left top width and height on an image using python 
Python :: How to send data to scrapy pipeline to mongodb 
Python :: 218922995834555169026 
Python :: argc python 
Python :: mo.group() separated with spaces instead of commas python 
Python :: how to call a function in python? 
Python :: Python Deleting Attributes and Objects 
Python :: Pandas dataframe with MultiIndex: check if string is contained in index level 
Python :: Indices may also be negative numbers, to start counting from the right:Indices may also be negative numbers, to start counting from the right: 
Python :: token validation in flask socket 
Python :: parsing date columns when reading csv 
Python :: initialise a 3D tab in python 
Python :: words repeating in word cloud python 
Python :: sanic ip whitelist 
Python :: restart kernel python 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =