Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to compare dates?

884 views
Skip to first unread message

Daniel Alexander

unread,
Dec 3, 1999, 3:00:00 AM12/3/99
to
I need to compare 2 dates where one is in the format dd-Mmm-yyy
($due_date) to see if $todays_date is within 14 days (2 weeks) of
approaching $due_date. This is going to be used to scan records in a
database to show me which ones are coming due in the next 14 days so I
know they are "hot". Example:

I have a $due_date of 15-Mar-2000 and $todays_date is (hypothetically)
07-Mar-2000 (in whateve format). I would want to know that I am 14 (or
less) from being overdue.

From reading the man pages I believe I should be able to use [clock
format] to convert 15-Mar-2000 into something I can compare to todays
date using a simple =< if statement. However, I am not exactly sure
how to go about it. Can anybody give me an example of how to convert
that date into something I can compare (within days) to whatever the
current date is?

Thanks in advance,

Daniel Alexander


Sent via Deja.com http://www.deja.com/
Before you buy.

Nuno Rodrigues

unread,
Dec 3, 1999, 3:00:00 AM12/3/99
to
This is the comversion you should do to put a date in yyyymmdd format.
clock format [clock seconds] -format "%Y%m%d"

Daniel Alexander <alex...@my-deja.com> wrote in message
news:828ptk$ard$1...@nnrp1.deja.com...

dhag...@my-deja.com

unread,
Dec 4, 1999, 3:00:00 AM12/4/99
to
Read through the docs for the "clock scan" command. Be wary,
however, as it really does not like dash separators, being a
bit US-centric (soon to be fixed in rev 8.3):

# Return -1 if date1 < date2, 0 if date1==date2, 1 if date1 > date2.
proc datecompare {date1 date2} {
regsub -all -- - $date1 " " date1
regsub -all -- - $date2 " " date2
set date1_t [clock scan $date1]
set date2_t [clock scan $date2]
if {$date1_t < $date2_t} {
return -1
} elseif {$date1_t > $date2_t} {
return 1
}
return 0
}

set due_date "15-Mar-2000"
set todays_date [clock format [clock seconds] -format "%m-%b-%Y"]
puts "comparison: [datecompare $todays_date $due_date]"

-=- D. J.

In article <828ptk$ard$1...@nnrp1.deja.com>,


Daniel Alexander <alex...@my-deja.com> wrote:
> I need to compare 2 dates where one is in the format dd-Mmm-yyy
> ($due_date) to see if $todays_date is within 14 days (2 weeks) of
> approaching $due_date. This is going to be used to scan records in a
> database to show me which ones are coming due in the next 14 days so I
> know they are "hot". Example:
>
> I have a $due_date of 15-Mar-2000 and $todays_date is (hypothetically)
> 07-Mar-2000 (in whateve format). I would want to know that I am 14 (or
> less) from being overdue.

0 new messages