Date Field Validation

I have to fields in database start_date and end_date. What I want to
validate is that start_date must be less than end_date. I want the
model level validation . Please help me.

Only way I know how to do this is to add your own validate method e.g.:

in your model…

def validate
errors.add(:start_date, “must be less than the end date”) if
start_date >= end_date

There might be a helper to do this, but at the time I wasn’t aware of
one so this is how I did it :wink:

Hope this helps.

  • Wayne

Thanks for your advice but I have tried that but it doesn’t work. Let
me clarify what I have in view file
Join Date:
<%=date_select :job_experience, :join_date,
:start_year=>, :end_year=>1900,

Left Date:
<%=date_select :job_experience, :left_date,
:start_year=>, :end_year=>1900,

Then I write the following in my model

def validate
errors.add_to_base("left date cannot be less than join date ") if

But the validation doesn’t work. Please Rails Lover give me some