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.

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).

I'm afraid that "Its Linux" is too wide a statement. Can you post the output from uname -a

Thanks, in advance,
Robin

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

22.01.2015_14:01

hth

1 Like

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

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?