ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to find the diffrenece between two dates.
for eg: time1: Tue Feb 14 14:43:12 IST 2006
time2: Tue Feb 14 15:50:09 IST 2006
Now I want the difference between time1&time2.(for eg:67min15seconds).
I need some logic for the above scenario in shell script.
It is very urgent.Can you please help me.
Convert both dates into Julian format (or timestamp), that is a fixed number of seconds from a given reference point, subtract them to get the difference in seconds and then convert that to the hours minutes second format that you desire
I want to find the diffrenece between two dates.
for eg: time1: Tue Feb 14 14:43:12 IST 2006
time2: Tue Feb 14 15:50:09 IST 2006
Now I want the difference between time1&time2.(for eg:67min15seconds).
I need some logic for the above scenario in shell script.
It is very urgent.Can you please help me.
Let me know if you find answers for this.I am also looking for same kind of script
Just divide the timestamp difference by $((60*60*24)) for the number of day's between two times. Your times are less than a day:
tdate1=$(date -d 'Tue Feb 14 15:50:09 IST 2006' +%s)
tdate2=$(date -d 'Tue Feb 14 14:43:12 IST 2006' +%s)
echo $tdate1, $tdate2
1139912409, 1139908392
echo $(( ($tdate1-$tdate2) / ( 60*60*24) ))
0
tdate2=$(date -d 'Tue Feb 14 14:43:12 IST 2006' +%s)
echo $(( ($tdate1-$tdate2) / ( 60) ))
66
echo $(( ($tdate1-$tdate2) / ( 60) )) minutes, $(( ($tdate1-$tdate2) % 60 )) seconds
66 minutes, 57 seconds
---
P.S. Did you read the man page for the date command?
Due to leap seconds, a delta time difference across a year boundary may not be reliable (depending on the time standard used). Wikipedia has an explanation. Also a mystery. The tidal effect slows down the earth's rotation by about a second per year. However, in the last few years, the earth's rotation has been speeding up.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.