Re: [foxboro] Date comparison in Unix scripts

  • From: "William C Ricker" <wcricker@xxxxxxxxxxxxxxx>
  • To: <foxboro@xxxxxxxxxxxxx>
  • Date: Thu, 18 Apr 2002 17:34:29 -0400

Terry,

For date storage and comparison purposes, it
is best to put the number fields in order
of Year, Month, Day.

Using the bourne shell (/bin/sh):

To generate this, i use the UNIX command:

   NOW=`date '+%Y%m%d'`

For today, this would produce a value in NOW
of 020418.

If your file has the date in a different form,
'awk' is usefull in switching fields around.

For example, if it is stored as 04/18/02, and
you have read that value into variable FILEDATE,
the string could be

   DATE=`echo $FILEDATE | awk '{printf "%s%s%s",
       substr($0,7,2), substr($0,1,2),substr($0,4,2)' -`

That would be all on one line, and watch the single
quote directions.

This could then be compared by:

  if [ $DATE -lt $NOW ] ; then
    ..do your time expired stuff..
  fi

Note that expanding the 'awk' program, you could also
compensate for lack of leading zero, etc. in the date
as read from the file.


Good Luck

William C. Ricker
FeedForward, Inc.
Marietta, GA, USA
wcricker@xxxxxxxxxxxxxxx
770-426-4422

-----Original Message-----
From: foxboro-bounce@xxxxxxxxxxxxx
[mailto:foxboro-bounce@xxxxxxxxxxxxx]On Behalf Of Deo, Terry
Sent: Thursday, April 18, 2002 4:34 PM
To: foxboro@xxxxxxxxxxxxx
Subject: [foxboro] Date comparison in Unix scripts



Does anyone know an easy way to compare dates in a Unix script?  I am
looking to read a date from a data file and compare it to the current system
date.  The idea is to determine when certain tasks are beyond the required
completion date.

Regards,
Terry

Terry J. Deo
Staff Systems Engineer
Infineum USA LP
Byway Chemical Plant, Linden, NJ
V: 908.474.6179
F: 908.474.7609








_______________________________________________________________________
This mailing list is neither sponsored nor endorsed by Invensys Process
Systems (formerly The Foxboro Company). Use the info you obtain here at
your own risks. Read http://www.thecassandraproject.org/disclaimer.html

foxboro mailing list:             //www.freelists.org/list/foxboro
to subscribe:         mailto:foxboro-request@xxxxxxxxxxxxx?subject=join
to unsubscribe:      mailto:foxboro-request@xxxxxxxxxxxxx?subject=leave


 
 
_______________________________________________________________________
This mailing list is neither sponsored nor endorsed by Invensys Process
Systems (formerly The Foxboro Company). Use the info you obtain here at
your own risks. Read http://www.thecassandraproject.org/disclaimer.html
 
foxboro mailing list:             //www.freelists.org/list/foxboro
to subscribe:         mailto:foxboro-request@xxxxxxxxxxxxx?subject=join
to unsubscribe:      mailto:foxboro-request@xxxxxxxxxxxxx?subject=leave
 

Other related posts: