Difference of dates

Login or Register to Reply

Thread Tools Search this Thread
# 1  
Difference of dates

I have a script which is printing date in below format while writing the logs.

theDate=`date +"%m%d%Y"`
theTime=`date +"%H%M%S"`
echo $theDate $theTime

How can i find out difference current time and above format. Appreciate your help.
# 3  
Originally Posted by Corona688
Options for date math vary quite a lot depending on your system.

What is your system?
Its Linux - I just want to find out the difference , something like (01212015 203238) - (01212015 201302) = 19(M):36(S).
# 5  
See date --help for your system specific date options.

On my RedHat based system Fedora, i could use either one of these two lines to get your 'now' time:
NOW=$(date +%F%T|sed s,-,,g|sed s,:,,g)
NOW=$(date +%d%m%Y%H%M)

However, if you can define the date-order yourself, I'd recomend to use this format: yyyymmddhhmmd, especially for logfiles.
You can use signs to make it better readable, but for doing math, they hinder.

NOW=$(date +"%d.%m.%Y_%H:%M")
echo $NOW



Last edited by rbatte1; 01-22-2015 at 09:57 AM..
This User Gave Thanks to sea For This Post:
# 6  
Originally Posted by rbatte1
I'm afraid that "Its Linux" is too wide a statement. Can you post the output from uname -a

Thanks, in advance,

Linux XXXXX.prod.XXXX.com 2.6.18-194.11.4.el5 #1 SMP Fri Sep 17 04:57:05 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
# 7  
You have told us the version of the 5-megabyte file which loads when you hit the power-button on your computer.

Everything else about your system, everything, is up to your distribution.

What is your distribution?
Login or Register to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Difference between two dates
Hi There I am trying to find the difference between two dates in seconds, by taking the first 10 digits of the file name itself, which I have done as shown below: current_time=`date +%s` last_login_of_tim=`date -d @1489662376 +%s` diff_sec=$(($current_time-$last_login_of_tim)) ...... UNIX for Beginners Questions & Answers
UNIX for Beginners Questions & Answers
Difference between 2 dates
Hi Friends, I have a file that has the contents like below: file1.txt 5,13/07/2013 23:25:25,14/07/2013 19:40:21 5,13/07/2013 23:25:25,14/07/2013 19:40:43 5,12/07/2013 23:50:50,13/07/2013 20:30:26 5,12/07/2013 23:20:24,13/07/2013 19:40:53 60,14/07/2013 00:00:00,14/07/2013 23:00:39...... Shell Programming and Scripting
Shell Programming and Scripting
Difference between two dates
hi all, I need a help for below requirement. Difference between two dates"12-11-2009" and "03-25-2012" (mm-dd-yy format") in weeks and days and hours Please help me for this. Thanks in adv.... I am working in AIX, so dont have below command:- date --version... Shell Programming and Scripting
Shell Programming and Scripting
Difference between two dates.
Hi all. My question may seems to be similar to one that already been here. But i need a little other solution. I have two dates in format dd/mm/yyyy. I need to find number of days between them. I need to do it in bash script. I am running on Solaris machine and have cutted 'date' command version...... Shell Programming and Scripting
Shell Programming and Scripting
Difference between two dates...
Hi All, Wish you a Happy New year... I have to find the difference between two dates, the result should be the number of days. I have seen the "datecalc" function. Its good, can I have any other alternative. Thanks in Advance Raju... Shell Programming and Scripting
Shell Programming and Scripting