Python Forum
Need to add hours min and seconds
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to add hours min and seconds
#1
Hi,
I have a problem adding HHMMSS.
Have a file, it goes like this:

5/1/2020 2:40:31 PM, 5/1/2020 2:43:11 PM, 00:02:40.5449136, PV0015EN,Cell_13, TT
5/1/2020 2:45:26 PM, 5/1/2020 2:48:17 PM, 00:02:50.8250927, PV0015EN,Cell_13, TT
5/1/2020 2:53:18 PM, 5/1/2020 2:56:01 PM, 00:02:43.7207947, PV0015EN,Cell_13, TT
5/1/2020 3:04:43 PM, 5/1/2020 3:05:42 PM, 00:00:59.2069877, PV0015EN,Cell_13, TT
5/1/2020 2:53:18 PM, 5/1/2020 2:56:01 PM, 00:02:43.7207947, PV0015EN,Cell_13, TT
5/1/2020 3:04:43 PM, 5/1/2020 3:05:42 PM, 00:00:59.2069877, PV0015EN,Cell_13, TT

The third column is a time duration and I need to sum it up.
I thought I will split each line, get the third column (timeduration) then will split it (will remove milliseconds) and add separately Minutes and Seconds.
And after that will convert using something like this:
sec= 66
fg= str(datetime.timedelta(seconds=sec))
print (fg)

min= 25
fm=str(datetime.timedelta(minutes=min))
print (fm)
I created little script but stuck Wall - do not know how to add my vars:
Her is my code:

import os
too = 'C:/01/OUTCOME.txt'

with open(too) as fo:        
            for line in fo:
                tu, on,ontu,*stu= line.split(',')
                ontu=ontu.rstrip()
                sd,st=ontu.split('.')
                #print (sd)
                sdh,sdm,sds=sd.split(':')
                print ("Minutes", sdm)
                print ("Seconds", sds)
Thanks in advance!
Reply


Messages In This Thread
Need to add hours min and seconds - by tester_V - Jun-02-2020, 01:00 AM
RE: Need to add hours min and seconds - by tester_V - Jun-02-2020, 04:36 AM
RE: Need to add hours min and seconds - by tester_V - Jun-02-2020, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with module time and leap seconds Pedroski55 3 1,333 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  MatplotibTicks every 24 hours TamP 4 1,258 Oct-04-2022, 04:08 PM
Last Post: deanhystad
  Hello all! need help. calculating OT hours. no1up 5 1,614 Jul-30-2022, 10:00 PM
Last Post: rob101
  Store variable data and display sum after 60 seconds the_dude 11 3,629 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  Py script that triggers ever 3 hours, but only between 9:15 am to 3:30 pm, Mon to Fri Pymod 2 1,902 Jun-30-2021, 05:14 PM
Last Post: Larz60+
  How to get utcnow + 2 hours? korenron 2 2,664 Mar-01-2021, 03:22 PM
Last Post: korenron
  How to calculate time difference between each row of dataframe in seconds Mekala 1 2,667 Jul-16-2020, 12:57 PM
Last Post: Larz60+
  Can't substract seconds from time Raj_Kumar 1 1,843 Apr-15-2020, 02:47 AM
Last Post: bowlofred
  How to calculate time in seconds rajeshE 1 2,159 Feb-15-2020, 11:07 PM
Last Post: Larz60+
  how to stop and start a script for 30 seconds laspaul 9 7,908 Jan-16-2020, 02:13 PM
Last Post: laspaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020