Solved

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

Posted on 2004-08-06
6
890 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now