Time Calculations & Conversions


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Time Calculations & Conversions
# 1  
Old 09-14-2007
Time Calculations & Conversions

I have script that runs based on time variables passed in the command line. The first command argument is a timer, in seconds, of how often to execute a certain loop in the script. The second command argument is the end time of the script, in military time. Below is an example of the command line:
Code:
% statreport 0360 1530

When the script is called I retrieve the current time. The problem I have is that I need to calculate the difference between the current time and end time then convert the difference to seconds. Is there any easy way to do this?

Thanks ahead of time.
# 2  
Old 09-14-2007
Break up the end-time into hours and minutes. (60*hours)+minutes gives you minutes past midnight. Use date command to get current hours and minutes and do likewise. Subtract to get difference in minutes. Multiply by 60 to convert to seconds.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

HD GB conversions

Sorry if this is in the wrong area. I am not sure where to put this question. HD manufacturers usually use the 1000 scale for measuring their HD capacity instead of 1024 which is way more common with computers. What would 750 GB on the 1000 scale convert to on the 1024 scale and how would you... (1 Reply)
Discussion started by: cokedude
1 Replies

2. UNIX for Advanced & Expert Users

Vi line endings conversions

I was reading these 2 articles. Why does the wikia one think :e ++ff=dos? Or am I just misunderstanding it? :e ++ff=unix :e ++ff=dos File format - Vim Tips Wiki Managing/Munging Line-Endings with Vi/Vim | Jeet Sukumaran (1 Reply)
Discussion started by: cokedude
1 Replies

3. Shell Programming and Scripting

Unix to Linux Conversions?

I have over 800 scripts (Korn and Perl) wrote on a Unix platform (Solaris) that I need to covert to a Linux platform (Redhat). All the path's and binaries need review. Are there any tools out there that would simplify or assist me with this conversion? (3 Replies)
Discussion started by: soupbone38
3 Replies

4. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

5. Shell Programming and Scripting

shell execution time calculations

I am writting a script in the ksh shell and am trying to find a way to report the total execution time of the script without requiring the user to specify the time function when executing the script. Does anyone have any examples they have used. I have been setting up two date variables (one at... (1 Reply)
Discussion started by: Omar Bacha
1 Replies

6. Shell Programming and Scripting

Perl date conversions

Is there a perl date conversion that will convert this type of date: 2008/100:01:56:10.000 to this type of date: 2008 04 09 01 56 10 000 I am using this right now: sub jd2date { $space=" "; $zero="0"; my ($jd) = @_; if (($jd<1) || ($jd>782028)) { print "julian... (5 Replies)
Discussion started by: ajgwin
5 Replies

7. UNIX for Dummies Questions & Answers

Time Calculations

I'm trying to have a loop print out statistics every X number of seconds. How can I add a specific number of seconds to a time variable and make a comparison? Thanks ahead of time. For example: startTime = `date +%H%M%S` currentTime = $startTime executeTime = startTime + X # X is equal... (5 Replies)
Discussion started by: Nysif Steve
5 Replies

8. Shell Programming and Scripting

problem doing the time calculations in shell.

I am trying to do a shell script to monitor if any files went through in the last hour. There is a script in cron that runs every sec checking to see if a file is there and ftp the file out of this folder. Now I just want to add a block of code that will check to see no files went in the last... (3 Replies)
Discussion started by: jonathan184
3 Replies

9. Shell Programming and Scripting

HP-UX & need help with time

I use HP-UX & need help with time. I use a script to create a date stamp: /bin/date "+%m%d%H%M" to get: 12080826. I need a way to use the "touch -t" command to create a file with a timstamp 30 minutes prior to that stamp. (12080756) Can anyone help? (9 Replies)
Discussion started by: obrien2003
9 Replies

10. Shell Programming and Scripting

Time difference calculations

Hi All.. Does anyone have a useful function where I can enter two date/timestamps and it calculates the difference in time in hours, minutes and seconds between the 2? Any feedback much appreciated. :D Kind Regards Satnam (1 Reply)
Discussion started by: satnamx
1 Replies
Login or Register to Ask a Question