# Date and Time validator, updater

**URL:** <https://www.ruby-forum.com/t/date-and-time-validator-updater/111878>\
**Category:** Rails\
**Created:** [August 12, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/date-and-time-validator-updater/111878 "2007-08-12T22:03:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 12, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/date-and-time-validator-updater/111878/1 "2007-08-12T22:03:30Z")

</div>

Can someone point me to a date/time validator or updater.

I have an event start datetime and an event end datetime. I want  
to validate that the end datetime is after the start datetime.

Figure there is some code or library out there already, if you  
know one, please forward it.

Thank you!

---

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 12, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/date-and-time-validator-updater/111878/2 "2007-08-12T22:31:32Z")

</div>

Scott Parks wrote:

> Can someone point me to a date/time validator or updater.
> 
> I have an event start datetime and an event end datetime. I want  
> to validate that the end datetime is after the start datetime.
> 
> Figure there is some code or library out there already, if you  
> know one, please forward it.

You don’t really need a library to do this, it’s as simple as:

def validate  
errors.add(“end”, “is before start”) unless start \<= end  
end

–  
Cheers,

- Jacob A.

---

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 12, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/date-and-time-validator-updater/111878/3 "2007-08-12T23:17:14Z")

</div>

Hi Scott,

> Can someone point me to a date/time validator or updater.
> 
> I have an event start datetime and an event end datetime. I want  
> to validate that the end datetime is after the start datetime.
> 
> Figure there is some code or library out there already, if you  
> know one, please forward it.

Jacob’s right, and if you’d like to do any further date/time validations  
you should take a look at the validates\_date plugin [1]. It’s got a neat  
feature set and is well written too.

[1] [http://svn.viney.net.nz/things/rails/plugins/validates\_date\_time](http://svn.viney.net.nz/things/rails/plugins/validates_date_time)

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.

---

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 13, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/date-and-time-validator-updater/111878/4 "2007-08-13T12:51:38Z")

</div>

Thank you! This looks to do what I need to solve and more! Thanks  
for the tip.  
-Scott

---

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 13, 2007, 12:50pm UTC](https://www.ruby-forum.com/t/date-and-time-validator-updater/111878/5 "2007-08-13T12:50:37Z")

</div>

You have got to be kidding me? It’s that easy? I think I need to  
get my  
head out of the book (examples) and read some of the more in depth  
articles.

Thank you!
