Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to calculate time duration in Linux? Post 303035412 by Neo on Thursday 23rd of May 2019 07:16:57 AM
Old 05-23-2019
It is always best to always get in the habit of converting time text string (formatted time) to a unix timestamp (a number).

Then, format the timestamp(s) math results as needed.

It's always best in programming to separate the time functions and processing of time from the formatting of strings, because it is trivial to convert strings to timestamps and timestamps to formatted strings.

FYI, Just about every date stored in our database here at unix.com is a unix timestamp. We generally don't store formatted date strings in DB tables (unless of course the date is part of some text in a 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
std::chrono(3cxx)														 std::chrono(3cxx)

NAME
std::chrono - SYNOPSIS
Classes struct duration duration struct duration_values duration_values struct system_clock system_clock struct time_point time_point struct treat_as_floating_point treat_as_floating_point Typedefs typedef system_clock high_resolution_clock typedef duration< int, ratio< 3600 > > hours typedef duration< int64_t, micro > microseconds typedef duration< int64_t, milli > milliseconds typedef duration< int, ratio< 60 > > minutes typedef system_clock monotonic_clock typedef duration< int64_t, nano > nanoseconds typedef duration< int64_t > seconds Functions template<typename _ToDur , typename _Rep , typename _Period > constexpr enable_if < __is_duration< _ToDur > ::value, _ToDur >::type duration_cast (const duration< _Rep, _Period > &__d)" template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > constexpr bool operator!= (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Clock , typename _Dur1 , typename _Dur2 > constexpr bool operator!= (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _Rep1 , typename _Period , typename _Rep2 > duration< typename __common_rep_type< _Rep1, typename enable_if <!__is_duration< _Rep2 > ::value, _Rep2 >::type >::type, _Period > operator% (const duration< _Rep1, _Period > &__d, const _Rep2 &__s)" template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator% (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)" template<typename _Rep1 , typename _Period , typename _Rep2 > duration< typename __common_rep_type< _Rep1, _Rep2 >::type, _Period > operator* (const duration< _Rep1, _Period > &__d, const _Rep2 &__s)" template<typename _Rep1 , typename _Period , typename _Rep2 > duration< typename __common_rep_type< _Rep2, _Rep1 >::type, _Period > operator* (const _Rep1 &__s, const duration< _Rep2, _Period > &__d)" template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator+ (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)" template<typename _Clock , typename _Dur1 , typename _Rep2 , typename _Period2 > time_point< _Clock, typename common_type< _Dur1, duration < _Rep2, _Period2 > >::type > operator+ (const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)" template<typename _Rep1 , typename _Period1 , typename _Clock , typename _Dur2 > time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+ (const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)" template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator- (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)" template<typename _Clock , typename _Dur1 , typename _Rep2 , typename _Period2 > time_point< _Clock, typename common_type< _Dur1, duration < _Rep2, _Period2 > >::type > operator- (const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)" template<typename _Clock , typename _Dur1 , typename _Dur2 > common_type< _Dur1, _Dur2 >::type operator- (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _Rep1 , typename _Period , typename _Rep2 > duration< typename __common_rep_type< _Rep1, typename enable_if <!__is_duration< _Rep2 > ::value, _Rep2 >::type >::type, _Period > operator/ (const duration< _Rep1, _Period > &__d, const _Rep2 &__s)" template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > common_type< _Rep1, _Rep2 >::type operator/ (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > constexpr bool operator< (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Clock , typename _Dur1 , typename _Dur2 > constexpr bool operator< (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > constexpr bool operator<= (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Clock , typename _Dur1 , typename _Dur2 > constexpr bool operator<= (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > constexpr bool operator== (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Clock , typename _Dur1 , typename _Dur2 > constexpr bool operator== (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > constexpr bool operator> (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Clock , typename _Dur1 , typename _Dur2 > constexpr bool operator> (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _Rep1 , typename _Period1 , typename _Rep2 , typename _Period2 > constexpr bool operator>= (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs) template<typename _Clock , typename _Dur1 , typename _Dur2 > constexpr bool operator>= (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs) template<typename _ToDur , typename _Clock , typename _Dur > constexpr enable_if < __is_duration< _ToDur > ::value, time_point< _Clock, _ToDur > >::type time_point_cast (const time_point< _Clock, _Dur > &__t)" Detailed Description ISO C++ 0x entities sub namespace for time and date. Typedef Documentation typedef duration<int, ratio<3600> > std::chrono::hours hours Definition at line 514 of file chrono. typedef duration<int64_t, micro> std::chrono::microseconds microseconds Definition at line 502 of file chrono. typedef duration<int64_t, milli> std::chrono::milliseconds milliseconds Definition at line 505 of file chrono. typedef duration<int, ratio< 60> > std::chrono::minutes minutes Definition at line 511 of file chrono. typedef duration<int64_t, nano> std::chrono::nanoseconds nanoseconds Definition at line 499 of file chrono. typedef duration<int64_t> std::chrono::seconds seconds Definition at line 508 of file chrono. Function Documentation template<typename _ToDur , typename _Rep , typename _Period > constexpr enable_if<__is_duration<_ToDur>::value, _ToDur>::type std::chrono::duration_cast (const duration< _Rep, _Period > &__d) [inline] duration_cast Definition at line 173 of file chrono. Referenced by std::this_thread::sleep_for(). template<typename _ToDur , typename _Clock , typename _Dur > constexpr enable_if<__is_duration<_ToDur>::value, time_point<_Clock, _ToDur> >::type std::chrono::time_point_cast (const time_point< _Clock, _Dur > &__t) [inline] time_point_cast Definition at line 575 of file chrono. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Nov 27 2012 std::chrono(3cxx)
All times are GMT -4. The time now is 05:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy