Forum OpenACS Development: Re: Compare Dates

Collapse
5: Re: Compare Dates (response to 1)
Posted by Don Baccus on
Here's an example using the form builder directly (as you're doing):
element create event_add end_time \
    -label "End" \
    -datatype date \ 
    -widget date \
    -format "MONTH DD YYYY HH12:MI AM" \
    -minutes_interval { 0 59 5 } \
    -help \
    -validate { \   
    { expr {[template::util::date::compare [template::element::get_value event_add start_time] $valu
e] < 0} } \
    {End time must be after start time} }

The validation clause calls the date comparison routine with start_time and end_time. The value for start_time must be retrieved usingn get_value because the validation clause is attached to the end_time form element. The value for end_time, the current form element when the validation clause is being executed, is directly available as "$value".

The comparison routine returns -1,0,1 depending on whether the first date is less, equal or greater than the second date param.

You should look into using ad_form, which is a wrapper procedure for the form template builder that simplfies its use considerably in many cases, and supports a validation block. Just grep the toolkit for "ad_form" for examples and documentation.