?
Solved

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

Posted on 2004-08-06
6
Medium Priority
?
933 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 252 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 248 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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 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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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