Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

convert timestamp hhmmss to seconds?

  • 30-01-2007 9:59pm
    #1
    Registered Users, Registered Users 2 Posts: 4,359 ✭✭✭


    Hi,

    i want to subtract two timestamps in unix, does anyone have a quick script for this? be it perl, shell whatever? the timestamp is of format hhmmss.


Comments

  • Registered Users, Registered Users 2 Posts: 1,421 ✭✭✭Steveire


    Here's some python:
    #!/usr/bin/env python
    import datetime
    def getDifference(timestamp1, timestamp2):
      hours1, minutes1, seconds1 = int(timestamp1[0:2]), int(timestamp1[2:4]), int(timestamp1[4:6])
      hours2, minutes2, seconds2 = int(timestamp2[0:2]), int(timestamp2[2:4]), int(timestamp2[4:6])
      t1 = datetime.datetime(1, 1, 1, hours1, minutes1, seconds1)
      t2 = datetime.datetime(1, 1, 1, hours2, minutes2, seconds2)
      difference = t1 - t2
      return difference.seconds
    
    timestamp1 = "112233"
    timestamp2 = "111010"
    print getDifference(timestamp1, timestamp2)
    # Prints 743
    


  • Registered Users, Registered Users 2 Posts: 4,359 ✭✭✭jon1981


    #!/usr/bin/perl
    
    
    sub convert_time{
    
    $time_in="$_[0]";
    $time_in=~/(\d{2})(\d{2})(\d{2})/;
    
    $hour = $1;
    $min = $2;
    $sec = $3;
    
    $time_sec = $sec + ($min*60) + ($hour*3600);
    
    }
    
    $time_end = $ARGV[0];
    $time_start = $ARGV[1];
    $duration = convert_time($time_end) - convert_time($time_start);
    print "$duration\n";
    
    cheers but i got off my lazy ass, this is crude but works


  • Registered Users, Registered Users 2 Posts: 2,747 ✭✭✭niallb


    You want crude? I'll give you crude :-)
    Bash style Shell - all on one line.
    for ts in 165959 090000 ; \
    do echo 60*$(echo $ts | cut -c 1-2,3-4,5-6 --output-delimiter="*60+")   ;\
     done | paste -d- - - | bc
    

    Ugly as sin, but when I press Return - I want answers :-)

    NiallB


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Do your own homework tbh. (A perl version of this thread was posted in the programming forum).


  • Registered Users, Registered Users 2 Posts: 4,359 ✭✭✭jon1981


    niallb wrote:
    You want crude? I'll give you crude :-)
    Bash style Shell - all on one line.
    for ts in 165959 090000 ; \
    do echo 60*$(echo $ts | cut -c 1-2,3-4,5-6 --output-delimiter="*60+")   ;\
     done | paste -d- - - | bc
    

    Ugly as sin, but when I press Return - I want answers :-)

    NiallB

    damn!!!


  • Advertisement
Advertisement