Unix/Linux Go Back    


Fedora is an operating system centered on the Linux open source kernel and is developed by the community-supported Fedora Project. Fedora is sponsored by Red Hat. Fedora contains software distributed under a free and open-source license. Fedora focuses on innovation, integrating and adopting new technologies and working closely with various Linux communities. The default desktop in Fedora is the GNOME desktop environment and the default user interface is the GNOME Shell. Other desktop environments include KDE Plasma, Xfce, LXDE, MATE and Cinnamon. Security is an important aspect of Fedora with one specific security feature, Security-Enhanced Linux, implementing a variety of software security policies, including mandatory access controls.

Difference of dates

Fedora


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-21-2015
srikanth38 srikanth38 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 31 May 2016, 12:42 PM EDT
Posts: 25
Thanks: 10
Thanked 3 Times in 3 Posts
Difference of dates

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


Code:
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.
Sponsored Links
    #2  
Old Unix and Linux 01-21-2015
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 January 2017, 5:46 PM EST
Location: Saskatchewan
Posts: 21,780
Thanks: 1,027
Thanked 4,038 Times in 3,746 Posts
Options for date math vary quite a lot depending on your system.

What is your system?
Sponsored Links
    #3  
Old Unix and Linux 01-21-2015
srikanth38 srikanth38 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 31 May 2016, 12:42 PM EDT
Posts: 25
Thanks: 10
Thanked 3 Times in 3 Posts
Quote:
Originally Posted by Corona688 View Post
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).
    #4  
Old Unix and Linux 01-22-2015
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 20 January 2017, 12:42 PM EST
Location: Lancashire, UK
Posts: 2,928
Thanks: 1,205
Thanked 544 Times in 492 Posts
I'm afraid that "Its Linux" is too wide a statement. Can you post the output from uname -a


Thanks, in advance,
Robin
Sponsored Links
    #5  
Old Unix and Linux 01-22-2015
sea sea is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 14 October 2016, 2:49 PM EDT
Location: Swissh
Posts: 1,285
Thanks: 256
Thanked 225 Times in 208 Posts
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:

Code:
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.


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

22.01.2015_14:01

hth

Last edited by rbatte1; 01-22-2015 at 10:57 AM..
The Following User Says Thank You to sea For This Useful Post:
srikanth38 (01-22-2015)
Sponsored Links
    #6  
Old Unix and Linux 01-22-2015
srikanth38 srikanth38 is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 31 May 2016, 12:42 PM EDT
Posts: 25
Thanks: 10
Thanked 3 Times in 3 Posts
Quote:
Originally Posted by rbatte1 View Post
I'm afraid that "Its Linux" is too wide a statement. Can you post the output from uname -a


Thanks, in advance,
Robin

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
Sponsored Links
    #7  
Old Unix and Linux 01-22-2015
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 20 January 2017, 5:46 PM EST
Location: Saskatchewan
Posts: 21,780
Thanks: 1,027
Thanked 4,038 Times in 3,746 Posts
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?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Difference between 2 dates vsachan Shell Programming and Scripting 5 07-17-2013 04:15 PM
Difference between two dates gani_85 Shell Programming and Scripting 2 03-29-2012 07:07 AM
Difference between two dates MalaTomi Shell Programming and Scripting 1 03-19-2010 05:21 PM
Difference between two dates. kukuruku Shell Programming and Scripting 1 09-30-2008 06:18 AM
Difference between two dates... rajus19 Shell Programming and Scripting 4 01-04-2006 04:53 AM



All times are GMT -4. The time now is 03:37 PM.