Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to calculate time duration in Linux? Post 303035411 by RudiC on Thursday 23rd of May 2019 07:10:56 AM
Old 05-23-2019
With Linux you should have GNU date available. Try


Code:
awk -F\|   '
        {printf "%s", "echo \"" $0 " |"
        }
NR == 1 {print " Duration\""
        }
NR > 1  {print  "$(( $(date +%s -d\"" $4 " " $5 "\") - $(date +%s -d\"" $2 " " $3 "\") )) \""
        }
' file | sh

SID   |   Date     |   Starttime   |Date         |End  time | Duration
 1607 |2019-04-05|13:06:42|2019-04-05|13:07:12 |30 
 2327 |2019-04-05|13:57:26|2019-04-05|13:57:43 |17


Two caveats:
1) with your data structure, the system won't know if you're talking 5th April, or 4th May.
2) Above will calculate difference in seconds only. No further formatting like HH:MM:SS will be done; that'll be up to you (search these fora, for example)
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Solaris

Finding list of modified files for a particular time duration

Hi , I am trying to find out the List of files modified or added aftter installation of any component on SUN solaris box . But i am not able to do it using ls or find command . Can somebody help me out ? Thanks Sanjay Gupta (2 Replies)
Discussion started by: sanajyg_mnit
2 Replies

2. Shell Programming and Scripting

date duration fail to calculate

Hi Everyone, I was very sad after a long way but still cannot figure out the duration between two date. $date1="20090812 23:48:56"; $date2="20090813 00:01:37"; The output will be "001241". I did the following tries, like print localtime(UnixDate(ParseDate("20090812 23:48:56"),"%s"));... (2 Replies)
Discussion started by: jimmy_y
2 Replies

3. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

4. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

5. Shell Programming and Scripting

Convert Date from File and Calculate Duration

Hi - I am looking for a little help to read in 2 date fields from a file in format: 20120508134012.3 yyyymmddhhmmss.tenths of a second So i want to: 1. Read in the 1st date from the file 2. Read in the second date from the file 3. Calculate the difference in minutes (or seconds) 4. ... (5 Replies)
Discussion started by: Newbie2012
5 Replies

6. Shell Programming and Scripting

Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in... (5 Replies)
Discussion started by: ks_reddy
5 Replies

7. Shell Programming and Scripting

Getting the Start, End time and duration using date command

Oracle Enterprise Linux We want to track how long a process takes to complete its execution. This is what we want in the schell script Before the process is started , get the time with date, hours and minutes execute the process After the process has ended , get the time with date,... (5 Replies)
Discussion started by: omega3
5 Replies

8. Shell Programming and Scripting

Perl ::duration of time in between dates

Hello All, I have two strings with date and time as follows.. $starttime= "06/11/2013 "; $starttime= "05:15"; $enddate="06/12/2013"; $endtime="04:45"; dates are in mm/dd/yyyy format and time in military format. and I am looking the duration of time(in minutes) in between dates. ... (3 Replies)
Discussion started by: scriptscript
3 Replies

9. UNIX for Dummies Questions & Answers

Script shell calculate mean arrival request duration

hello, I have implemented this command : tshark -eth0 -T fiels -e frame.time et sip.Request-Line -z sip,stat > test2.txt the result of this command : test.txt: Aug 27, 2013 23:06:47.334270000 INVITE Aug 27, 2013 23:06:47.335045000 SIP/2.0 401 Unauthorized Aug 27, 2013... (1 Reply)
Discussion started by: Amouna
1 Replies

10. UNIX for Dummies Questions & Answers

How to list files for particular duration of time .?

Hi there is a lot of file dated from last week till ofpresent date. if i want to list only last 3 days files using ls command how can i do it please suggest. below is the list of the file. and i want to list files from MAy 12 to May 16. Nov 22 2011 NSSM.UPPLSCPLB81 Jan 12... (2 Replies)
Discussion started by: scriptor
2 Replies
MooseX::Types::ISO8601(3pm)				User Contributed Perl Documentation			       MooseX::Types::ISO8601(3pm)

NAME
MooseX::Types::ISO8601 - ISO8601 date and duration string type constraints and coercions for Moose SYNOPSIS
use MooseX::Types::ISO8601 qw/ ISO8601TimeDurationStr /; has duration => ( isa => ISO8601TimeDurationStr, is => 'ro', coerce => 1, ); Class->new( duration => 60 ); # 60s => PT00H01M00S Class->new( duration => DateTime::Duration->new(%args) ) DESCRIPTION
This module packages several TypeConstraints with coercions for working with ISO8601 date strings and the DateTime suite of objects. DATE CONSTRAINTS
ISO8601DateStr An ISO8601 date string. E.g. "2009-06-11" ISO8601TimeStr An ISO8601 time string. E.g. "12:06:34Z" ISO8601DateTimeStr An ISO8601 combined datetime string. E.g. "2009-06-11T12:06:34Z" ISO8601DateTimeTZStr An ISO8601 combined datetime string with a fully specified timezone. E.g. "2009-06-11T12:06:34+00:00" COERCIONS The date types will coerce from: " Num " The number is treated as a time in seconds since the unix epoch " DateTime " The duration represented as a DateTime object. " Str " Non-expanded date and time string representations. e.g.:- 20120113 => 2012-01-13 170500Z => 17:05:00Z 20120113T170500Z => 2012-01-13T17:05:00Z Representations of UTC time zone (only an offset of zero is supported) e.g.:- 17:05:00+00:00 => 17:05:00Z 17:05:00+00 => 17:05:00Z 170500+0000 => 17:05:00Z 2012-01-13T17:05:00+00:00 => 2012-01-13T17:05:00Z 2012-01-13T17:05:00+00 => 2012-01-13T17:05:00Z 20120113T170500+0000 => 2012-01-13T17:05:00Z Also supports non-standards mixing of expanded and non-expanded representations e.g.:- 2012-01-13T170500Z => 2012-01-13T17:05:00Z 20120113T17:05:00Z => 2012-01-13T17:05:00Z DURATION CONSTRAINTS
ISO8601DateDurationStr An ISO8601 date duration string. E.g. "P01Y01M01D" ISO8601TimeDurationStr An ISO8601 time duration string. E.g. "PT01H01M01S" ISO8601DateTimeDurationStr An ISO8601 comboined date and time duration string. E.g. "P01Y01M01DT01H01M01S" COERCIONS The duration types will coerce from: " Num " The number is treated as a time in seconds " DateTime::Duration " The duration represented as a DateTime::Duration object. The duration types will coerce to: " Duration " A DateTime::Duration, i.e. the " Duration " constraint from MooseX::Types::DateTime. SEE ALSO
o MooseX::Types::DateTime o DateTime o DateTime::Duration o DateTime::Format::Duration VERSION CONTROL
http://github.com/bobtfish/moosex-types-iso8601/tree/master Patches are welcome. SEE ALSO
o http://en.wikipedia.org/wiki/ISO_8601 o http://dotat.at/tmp/ISO_8601-2004_E.pdf FEATURES
Fractional seconds If provided, the number of seconds in time types is represented to microsecond accuracy. A full stop character is used as the decimal seperator, which is allowed, but deprecated in preference to the comma character in ISO 8601:2004. BUGS
Probably full of them, patches are very welcome. Specifically missing features: o No timezone support - all times are assumed UTC o No week number type o "Basic format", which lacks seperator characters, is not supported for reading or writing. o Tests are rubbish. AUTHOR
Tomas Doran (t0m) "<bobtfish@bobtfish.net>" Dave Lambley "<davel@state51.co.uk>" The development of this code was sponsored by my employer <http://www.state51.co.uk>. Contributors Aaron Moses COPYRIGHT
Copyright (c) 2009 Tomas Doran. Some rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-05-11 MooseX::Types::ISO8601(3pm)
All times are GMT -4. The time now is 09:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy