Go Back   The UNIX and Linux Forums > Operating Systems > Solaris
Search Forums:



Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-19-2011
Registered User
 

Join Date: Jul 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Date comparison

Date comparison

Hello all

I am writing a scrip that will take action so long as the date with in the file is older than 3 months. The file will contain multiple rows of data. Each row will probably start with the date. My question... What is the exact code that should be used for date comparison. I am thinking

if date A > current date
Then
do task...
else
fi

will Date A > current date surfice?

Last edited by UofU; 01-19-2011 at 01:13 PM.. Reason: typo
Sponsored Links
    #2  
Old 01-19-2011
Registered User
 

Join Date: Oct 2010
Location: Southern NJ, USA (Nord)
Posts: 2,323
Thanks: 5
Thanked 282 Times in 265 Posts
Well, YYYY-MM-DD HH:MM:SS date-time compares right as strings, so generally the quickest way to compare is to shuffle the bytes around to that format.

To generate the date 3 months ago in that format, you need date arithmetic, usually the realm of C/C++/JAVA/PERL/etc., with leap year knowledge for month lengths and such. Some of the later shells, like ksh93 and certainly bash, have date arithmetic. Is this 3 months = 90 days or varying?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Date comparison using ksh informix2009 Shell Programming and Scripting 4 01-04-2010 05:53 PM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Homework & Coursework Questions 1 10-08-2009 01:27 PM
date comparison in bash carp.dk Shell Programming and Scripting 6 07-17-2009 09:44 AM
Date comparison sumesh.abraham Shell Programming and Scripting 6 12-14-2006 12:28 AM
date comparison dkr123 Shell Programming and Scripting 2 07-07-2006 09:09 PM



All times are GMT -4. The time now is 05:37 AM.