# Date precedence validation (ex. Round Trip travel dates)

**URL:** <https://www.ruby-forum.com/t/date-precedence-validation-ex-round-trip-travel-dates/174512>\
**Category:** Rails\
**Created:** [August 27, 2009, 10:44pm UTC](https://www.ruby-forum.com/t/date-precedence-validation-ex-round-trip-travel-dates/174512 "2009-08-27T22:44:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axinte\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Axinte\_L](https://www.ruby-forum.com/u/Axinte_L)\
**Post date:** [August 27, 2009, 10:44pm UTC](https://www.ruby-forum.com/t/date-precedence-validation-ex-round-trip-travel-dates/174512/1 "2009-08-27T22:44:22Z")

</div>

Hello,  
I’m trying to validate 2 dates that were provided by the user using a  
form  
that wraps a model.

I want to do the following 2 validations in the model:  
\*\*\*\* validate the date format =\> That I know how to do!  
\*\*\*\* if the format validation was a success, then ensure that date1 is  
smaller or equal than date2 =\> That’s I do not know

I’ve spend, in vain, more than 2 hours to find a solution in order to  
understand:  
\*\* 1 \*\* How to trigger a second validation only if the first one was  
an success?  
\*\* 2 \*\* How to compare to dates using the macros in ActiveRecord?

Any ideas?  
Kind regards  
Axinte

---

<div class="post-metadata">

**Author:** ![Axinte\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Axinte\_L](https://www.ruby-forum.com/u/Axinte_L)\
**Post date:** [August 28, 2009, 1:44am UTC](https://www.ruby-forum.com/t/date-precedence-validation-ex-round-trip-travel-dates/174512/2 "2009-08-28T01:44:08Z")

</div>

2009/8/27 Axinte L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> anÂ success?  
> Not sure about this, you may have to provide your own validate method  
> in the model rather than use the built in ones (or as well as)

> \*\* 2 \*\* How to compare to dates using the macros in ActiveRecord?

Assuming they are ruby Dates or Times or DateTimes just compare them  
using \<= or whatever.

Colin

---

<div class="post-metadata">

**Author:** ![Axinte\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Axinte\_L](https://www.ruby-forum.com/u/Axinte_L)\
**Post date:** [August 28, 2009, 2:12am UTC](https://www.ruby-forum.com/t/date-precedence-validation-ex-round-trip-travel-dates/174512/3 "2009-08-28T02:12:14Z")

</div>

Why not convert each date to Ruby Time objects and compare those?

–wpd

---

<div class="post-metadata">

**Author:** ![Axinte\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/43a26b/32.png) [@Axinte\_L](https://www.ruby-forum.com/u/Axinte_L)\
**Post date:** [August 28, 2009, 9:39am UTC](https://www.ruby-forum.com/t/date-precedence-validation-ex-round-trip-travel-dates/174512/4 "2009-08-28T09:39:31Z")

</div>

> Any ideas?  
> Kind regards  
> Axinte

validates\_date\_time plug in may help…
