You're getting a bad number error because -ge instructs the test command to do a numeric compare and your dates are alphanumeric. This isn't pretty, but it does work:
Code:
#!/usr/bin/env ksh
# dates1 and 2 on command line (dd-MMM-yyyy) are converted to yyyymmdd
# and numerically compared. A single digit is written to stdout to indicate the relationship:
# -1 when d1 < d2
# 0 when equal
# 1 when d1 > d2
#
function cmp_dt
{
awk -v d1=$1 -v d2=$2 '
BEGIN { soup = "JanFebMarAprMayJunJulAugSepOctNovDec";
split( d1, sd1, "-" );
split( d2, sd2, "-" );
m1 = int(index( soup, sd1[2] ) / 3) + 1;
m2 = int(index( soup, sd2[2] ) / 3) + 1;
id1 = sprintf( "%4d%02d%02d", sd1[3], m1, sd1[1] )+0;
id2 = sprintf( "%4d%02d%02d", sd2[3], m1, sd2[1] )+0;
print (id1 > id2 ? 1 : 0 id1 < id2 ? -1 : 0);
}'
}
# assign datenow and dbdate
if (( $(cmp_dt $dbdate $datenow) >= 0 ))
then
echo "date rolled over"
else
echo "date is ok"
fi
Should work in bash too, but I didn't test it there.
Last edited by agama; 12-02-2011 at 01:29 AM..
Reason: better comment
HI,
I am able to find days difference using FIND command. However it is comparing between today and the last time it was modified.
I now need to find the difference between a date specified by myself and the last time the file was modified. Is there a command which I can use or I have to... (1 Reply)
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... (7 Replies)
Hi All.
Can someone please give me an example of how I'd do a comparison to find out if the last modified date of a file is newer than yesterday (i.e. today - 1 day)?
Example:
if ; then
echo "Do something..."
fi
Any ideas or examples?
Thanks. (1 Reply)
Hi guys
I have a a variable called check_ts which holds a date value. this date value keeps refreshing every 15 minutes.
I am going to start a cron job 5 minutes after the refresh. I have to check if the current date > 20 min of check_ts. how do i do that.
thanks
ragha (17 Replies)
Hi I have yesterday date and todays date stored in two variables.
Today date is stored in variable -- testdate=`date +%m/%d/%Y`
I found the yesterday date and stored in variable -- ydate=$month'/'$day1'/'$year
Now i am trying to find out whether $testdate is less that $ydate.
I am... (6 Replies)
Hi,
I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing.One more condition is change of year also i.e today is Jan1 2012 and yesterday is Dec 31 2011.
The above rek i want in Shell... (4 Replies)
Hi,
can we do date comparisons in unix? like if i give the two dates find which date is old one and which is new one and difference between the two dates in terms of hours,minutes,days and months. (1 Reply)
Hi
I am failing to write a script which compares a list of dates in a file with today's date.
OS: Solaris 10
I have a file which has server names & dates, i need to compare the date in this file with today's date, if it is less than today it should print the server name.
code i tried is ... (3 Replies)
Discussion started by: nanz143
3 Replies
LEARN ABOUT CENTOS
tartdates
tartdates(5) LinuxTaRT Special Dates tartdates(5)NAME
tartdates - Special date configuration for LinuxTaRT
DESCRIPTION
LinuxTaRT uses a configuration file called specialdates to enable the user to display a specific tagline on certain special dates. The name
and location of this file is specified in the LinuxTaRT configuration file ~/.tartrc, but is usually:
~/.tartdates
PARAMETERS
Each line of the special date file consists of a day of the year expressed as a two digit month, a forward-slash (/), a two digit date, a
colon (:) and a line of text.
mm/dd:tagline text
Any line that does not conform to this specification will be treated as a comment. Comments may also be specified by prefixing text with a
# symbol. Using this method, you can place a comment behind a date line.
EXAMPLES
01/01:Happy New Year!!
Will use "Happy New Year!!" as the tagline when the date is January 1st.
12/25:Merry Christmas to all!
Displays "Merry Christmas to all!" as your tagline on Christmas day.
FILES
~/.tartdates
SEE ALSO tart(1)tartrc(5)tart-custom(5)Mark Veinot 1.0.0 tartdates(5)