How to Calculate Time Difference?
Hi,
I want to calculate time difference, i tried below steps however getting some error: let say.. current_time=22:18 and previous_time=22:01 . i tried as diff=$(($current_time - $previous_time)) error: syntax error:operand expected(error token is "22:18 - 22:01" could someone please help me to calculate the diff? Thanks in advance :-) |
Have a look at this:
Code:
#!/bin/bash Code:
$ ./time.diff.sh 22:18 22:01 Code:
#!/bin/bash Code:
$ ./full.date.sh |
If you are using "GNU date" (which would be what's installed on most Linux systems these days):
Code:
let DELTA_SECONDS=(`date +%s -d "1/2/2013 00:00:00"`-`date +%s -d "1/1/2013 00:00:00"`) |
Issue Resolved
Followed the steps provided by you and its working fine..
Thanks a lot for all your help and time :-) |
How to Calculate Time Difference? Reply to Thread
Hi,
as i need a time difference in min, i am doing this: a=$(date -d "$curr_date $curr_time" +%M ) b=$(date -d "$fps_validated_date $fps_validated_time" +%M ) diffmin=$(( $a - $b )) however i am getting below errors: 1. a=$(date -d "$curr_date $curr_time" +%M) date: invalid date `29/11/13 07:15' 2. b=$(date -d "$fps_validated_date $fps_validated_time" +%M ) date: invalid date `29/11/13 06:32' how to resolve it? |
Use a valid date.
This is a valid date: 2013/11/29 07:15 and this is not a valid date: 29/11/2013 07:15 Date should be in this format: YYYY/mm/dd HH:MM:SS EDIT: The code in post #5 will probably not do what you expect it to do. Have a look at the following example: Code:
#!/bin/bash Code:
$ ./foo.sh |
How to Calculate Time Difference?
Actually there is a file with date as 29/11/13 07:15 and according to this i converted the system time in the similar format.
If i want to read this date 29/11/13 07:15 from a file and convert it into the format 2013/11/29 07:15, is there a way to convert it ? and then we can take a time difference? |
Converting 29/11/13 07:15 into 2013/11/29 07:15:
Code:
$ foo="29/11/13 07:15" |
Using ddiff (from dateutils) makes calculating date and time differences easy:
Code:
$ ddiff 22:01 22:18 |
Thanks a lot, its really good :-)
|
All times are GMT -5. The time now is 11:38 AM. |