Time difference in seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time difference in seconds
# 1  
Old 06-18-2010
Time difference in seconds

Code:
date1=$(date +"%H:%M:%S")
date2=$(date +"01:00:54")
diff=$date2-$date1
echo $diff

How to get the time difference in seconds.
# 2  
Old 06-18-2010
i m nt sure why do u wana get second difference like this.if u can tell us in more details we can help u better..
bt i think this below will help u
Code:
CAR=`date +%Y%m%d%H%M%S`
CAR2=`date +%Y%m%d%H%M%S`

the above code will give u date in the below format
Code:
date +%Y%m%d%H%M%S ; date
20100618095508
Fri Jun 18 09:55:08 2010

so the last 2 digit is ur seconds. u can then do the expr command and get the result of ur difference.
# 3  
Old 06-18-2010
Hi,

Code:
diff=$(( $(date -d"$date2" +%s) - $(date -d"$date1" +%s) ))

GNU date again..
# 4  
Old 06-18-2010
I have to run the script at YYYY-MM-DD 01:10:54

./abc.sh PMW 2010-06-17 01:00:54

without cron.

If I execute the script at 00:10:22, i have to make the script sleep till 01:10:54 time and then execute.

So to take the difference of HH:MM:SS and convert to sec and I can make the script sleep for n sec.
# 5  
Old 06-18-2010
Code:
date +%Y%m%d%H%M%S

then i think this will do..

this will give u date in numerical manner and seconds and then minutes before second.
and u can comparison this easily
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting seconds to time

I have a list of time spans in seconds, and want to compute the time span as hh:mm:nn I am coding in bash and have coded the following. However, the results are wrong as "%.0f" rounds the values. Example: ftm: 25793.5 tmspan(hrs,min,sec): 7.16 429.89 25793.50 hh: 7 mm: 10 ss:... (2 Replies)
Discussion started by: kristinu
2 Replies

2. Shell Programming and Scripting

Time in seconds on AIX 4.3.2.0

Hi to everybody again i Need your help, i wasting hours but can't find a solutuin for my Problem. I am not an expert with AIX script programming. I have a csh script and i need the time in seconds but since i have an old AIX the Option -%s doesnot exist with the date command. I seach in Google... (13 Replies)
Discussion started by: Nadielosabra
13 Replies

3. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

4. Shell Programming and Scripting

datetime difference in seconds

Hi, I'm trying to find processing time of my script. Please can someone give me the commands to get the start/end time in "dd-mm-yyyy hh:mm:ss" and the differnce in seconds. Thanks! (5 Replies)
Discussion started by: dvah
5 Replies

5. Shell Programming and Scripting

Elapsed time in seconds in awk

I am trying to get the ellapsed time in seconds in the body of the awk script. I use unix date to get the time. It works in BEGIN {} but not in the body {} of awk. Any ideas? $ cat a BEGIN { "date +%s" | getline x print x } { "date +%s" | getline y print y } $ echo "one line" |... (3 Replies)
Discussion started by: arturas123
3 Replies

6. Shell Programming and Scripting

Get Current Time in Seconds Perl

hi guys, i need to know how to get the current date/time in seconds and i want to be able to do this in a one liner. like say for instance, if want to get what the time is right now, i'll issue a command like this: ## perl -e ' print scalar(localtime(time + 0)), "\n"' Tue Jul 13 17:45:50... (4 Replies)
Discussion started by: SkySmart
4 Replies

7. Shell Programming and Scripting

File creation time in seconds

Hi All, Cany any one help me in solving this.. Problem statement: I have a requirement to find the time from which there are no files created in a given directory. For this I am assuming that I need to get the file creation time in seconds, then the current time in seconds using `date +%s`.... (7 Replies)
Discussion started by: chary
7 Replies

8. Shell Programming and Scripting

Difference in day-hours-minutes-seconds format

Hi experts, I am reading two log files and passing dates as output to a txt file. Code is given below: echo "Start Time:" >> Report.txt cat start.log | while read LINE1 do echo $DATE1 >> Report.txt done echo "End Time:" >> Report.txt cat end.log | while read LINE2 ... (7 Replies)
Discussion started by: Sreejith_VK
7 Replies

9. UNIX for Advanced & Expert Users

Time Difference in seconds

It is required to calculate time difference in seconds between epoch time (19700101 00:00:00) and any given date time (e.g. 20010214 14:30:30). Is there any command in unix to get it? Thanks in adv. (1 Reply)
Discussion started by: k_bijitesh
1 Replies

10. UNIX for Dummies Questions & Answers

getting time in mili seconds

hi all UNIX Gurus, this is my first post...so i posting this with great expectations:o...hoping to get the similar replies... my question is.... need to get timestamp with millisecond in UNIX. Date command gives Year,month day, hour,minute and second but it does not give millisecond. Any... (5 Replies)
Discussion started by: Bhups
5 Replies
Login or Register to Ask a Question