Solved

"date2 - date1": elapsed time in hrs, mins, and secs

Posted on 2004-08-06
6
920 Views
Last Modified: 2010-04-21
How to calculate the elapsed time in hrs, mins, and secs:

For example, in the script, it has

d1=`date`
......
d2=`date`

How to get the time difference between d2 and d1.

Thanks.
0
Comment
Question by:geermu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 63 total points
ID: 11733410
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11748780
As an alternative.

man time
0
 
LVL 7

Assisted Solution

by:glassd
glassd earned 62 total points
ID: 11771799
Perl's Date::Calc module is ideal for this task.
0
 
LVL 5

Expert Comment

by:ITcrow
ID: 11865515

You have multiple options here:

perl:  
$start_time = time();
<Your Script Here>
$end_time  = time();
$time_taken =  $start_time - $end_time;

Or use some CPAN module: benchmark, Date::Calc, etc.

*nix Shell Cmd Line:
prompt> time <Your Script Here>

I am not aware which shell you are working in. Otherwise I could have suggested
a shell specific calculation.

Use of perl will make it Shell and OS independent, which is a good thing in long run.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question