The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing dates ragha81 Shell Programming and Scripting 17 10-25-2006 05:38 PM
Comparing two dates guptan Shell Programming and Scripting 5 11-25-2005 11:46 AM
Comparing last modified dates dmilks Shell Programming and Scripting 1 08-16-2005 09:01 PM
comparing dates svh High Level Programming 2 07-19-2005 10:04 AM
comparing 2 dates in Bourne shell scmay Shell Programming and Scripting 1 04-28-2004 07:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 1.00 average. Display Modes
  #1 (permalink)  
Old 11-13-2004
k_oops9 k_oops9 is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 11
Unhappy comparing 2 dates

hi ,

I have two variables both containg dates,

x= `date`
and
y= `date'

their format being -> Fri Nov 12 22:59:50 MST 2004

how do I compare which one is greater.

->Can dates be converted into integer and then compared?

( one lengthy way would be to compare the words one by one (i.e., first compare year then month then day....) )
But is their a simpler way of


can any one help me please.

Thanks

Last edited by k_oops9; 11-13-2004 at 02:29 AM..
  #2 (permalink)  
Old 11-13-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
See the FAQ by navigating
our home page -> Answers to Frequently Asked Questions -> Yesterdays Date/Date Arithmetic
  #3 (permalink)  
Old 11-14-2004
AbEnd AbEnd is offline
Registered User
  
 

Join Date: Sep 2003
Location: Canada
Posts: 56
Sure, use UNIX timestamps (ie, the number of seconds since 1970).
Code:
date +%s
  #4 (permalink)  
Old 11-14-2004
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
date +%s

works for GNU date only ....
  #5 (permalink)  
Old 11-15-2004
moxxx68's Avatar
moxxx68 moxxx68 is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 301
Unix is used loosely with both Unix and Linux the assumption goes with date +%s "unix"...
unless the original post specified otherwise.
what you are claiming is a little irrelevant its off topic and doesn't help the opriginal poster solve their problem..
do you have a better answer.. ifact do you know what flavour of Unix the original poster is uisng.. since linux is basically unix.

try gawk "substrings" to compare strings as you would in C just put the whole value of the time stamp in a variable and compare using the awk string comparison command..(awk is basically a language not a command so it will do the job just as you want) you will have to look it up in the man pages or try http://www.sourceforge.net to get the exact command since I am little rusty on awk..
moxxx68
  #6 (permalink)  
Old 11-15-2004
AbEnd AbEnd is offline
Registered User
  
 

Join Date: Sep 2003
Location: Canada
Posts: 56
Quote:
Originally posted by bhargav
date +%s

works for GNU date only ....
Works for *BSD's date too.
  #7 (permalink)  
Old 11-15-2004
moxxx68's Avatar
moxxx68 moxxx68 is offline
Registered User
  
 

Join Date: Mar 2004
Posts: 301
thank you for your input...
that what I was questioning that proves my point..
date +%s is the relavent answer
moxxx68
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0