# Datetime\_select validation

**URL:** <https://www.ruby-forum.com/t/datetime-select-validation/81923>\
**Category:** Rails\
**Created:** [January 16, 2007, 9:14am UTC](https://www.ruby-forum.com/t/datetime-select-validation/81923 "2007-01-16T09:14:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joepmath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@joepmath](https://www.ruby-forum.com/u/joepmath)\
**Post date:** [January 16, 2007, 9:14am UTC](https://www.ruby-forum.com/t/datetime-select-validation/81923/1 "2007-01-16T09:14:37Z")

</div>

I’m using a datetime\_select. When I select an invalid date like 31  
february 2007 it’s received by the model as 3 march 2007. I would like  
to generate a nice error for the user, but the only option I see now is  
hack this into the controller. Not so nice…

Joep Mathijssen

---

<div class="post-metadata">

**Author:** ![joepmath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@joepmath](https://www.ruby-forum.com/u/joepmath)\
**Post date:** [January 16, 2007, 11:15am UTC](https://www.ruby-forum.com/t/datetime-select-validation/81923/2 "2007-01-16T11:15:34Z")

</div>

Hi Joep,

if you’re using datetime\_select to set a DateTime property in your  
model, then you might want to consider using the pluging from Jonathan  
Viney available at:

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

This plugin can validate dates and times with some extra constraints  
(:before, :after, …) for properties of your model. There are some  
small examples at:

[http://www.railsonwave.com/railsonwave/2006/12/13/howto-validate-date-format-in-ruby-on-rails](http://www.railsonwave.com/railsonwave/2006/12/13/howto-validate-date-format-in-ruby-on-rails)

You may want to replace the parse\_date function in parser.rb with the  
one from Matt G. explained at:

[http://mattgriffith.net/Permalink.aspx?guid=4740f630-85db-4a4c-b199-8445b345f4f4](http://mattgriffith.net/Permalink.aspx?guid=4740f630-85db-4a4c-b199-8445b345f4f4)

If you only want to select dates then you’re better off with  
date\_select:

> **[ActionView::Helpers::DateHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M000469)**
>
> Action View Date Helpers The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time elements.

Kind regards,

Mark

---

<div class="post-metadata">

**Author:** ![joepmath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@joepmath](https://www.ruby-forum.com/u/joepmath)\
**Post date:** [January 16, 2007, 11:44am UTC](https://www.ruby-forum.com/t/datetime-select-validation/81923/3 "2007-01-16T11:44:52Z")

</div>

Hi, please search this group because I have answered this question.

Good luck,

-Conrad
