Subject: Re: How to compare dates? - DN [1]
dhagberg@my-deja.com - 04 Dec 1999 - comp.lang.tcl
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 <alexandl@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.
Sent via Deja.com http://www.deja.com/
Before you buy.
Last modified
1999-12-10
1999-12-10
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
