Search code examples
pythontimedatetime-conversion

Time conversion to a path file


I have a path files which are named by time (201803061500) etc. What I need is a time conversion, because I use while loop to open a few of them there is an error when I want files from for example (...1555 to ... 1615) and Python sees an obivous problem because after 1555 is 1560, but I want him to convert that to time so after (...1555 will be ... 1600) any ideas how to use it?

Btw. Time conversion must be contain 4 digits, so it cannot be 16:00/16-00 etc. it must be 1600, because it goes as an input to my pathfile. Any ideas?

UPDATE - I did this, but this code is rubbish and I think my problem might be solved by one command.

Start_time_hours = input('Enter start time (hh): ' )
Start_time_minutes = input('Enter start time (mm): ')

if Start_time_hours >= 24:
    print ("Values from 00 to 23 only!")
if Start_time_minutes >= 60:
    x = Start_time_hours + 1
    y = Start_time_minutes - Start_time_minutes
    if y == 0:
        print "Ok"
        print x, y

if Start_time_minutes <= 55:
        print Start_time_hours, Start_time_minutes

Solution

  • Start_time_hours += (Start_time_minutes / 60)
    Start_time_minutes %= 60
    Start_time_minutes += 5
    

    Those three lines solved my problem, datetime also works, but if you put those variables to input pathfile, you'll get an error. That's why I've choosen this solution.