# Date\_select vs wrong date weird behavior

**URL:** <https://www.ruby-forum.com/t/date-select-vs-wrong-date-weird-behavior/152232>\
**Category:** Rails\
**Created:** [October 31, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/date-select-vs-wrong-date-weird-behavior/152232 "2008-10-31T16:44:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [October 31, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/date-select-vs-wrong-date-weird-behavior/152232/1 "2008-10-31T16:44:03Z")

</div>

In my date\_select if I choose 31 april 2008, it converts it for 1st may  
2008 which it seems odd for me?

I say odd because first its difficult to validate at the model level, I  
have to hook some code in the controller and secondly when I finally get  
the validation errors I have to go back at the edit page and show the  
selected date(and the error message) which should be 31 april 2008 but  
the date is now 1st april 2008.

Any suggestion?

I know it should be better to have a calendar instead of a date\_select  
but I can’t.

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [November 1, 2008, 8:38am UTC](https://www.ruby-forum.com/t/date-select-vs-wrong-date-weird-behavior/152232/2 "2008-11-01T08:38:43Z")

</div>

I’m not sure about that “should be 31 April” since every April I’ve  
ever experienced has only had 30 days. Your first statement “it  
converts it for 1st may” actually seems to be correct behavior if  
you’re riding on time’s arrow.

Rick

On Oct 31, 5:44 am, Rémi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [November 1, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/date-select-vs-wrong-date-weird-behavior/152232/3 "2008-11-01T15:31:29Z")

</div>

Let me clarify.

The date\_select help generates 3 combobox, days, months and year. So  
for a user it is possible the select in days 31 for april, I know its a  
wrong date that’s why I want to nofify the user that he entered a wrong,  
but when I display the page back whit the error the date has changed to  
may 1st. I would like to show him the date\_select with 31 april 2008  
with the error on the site “Wrong date!”

So we that behavior, which is better to a crash(like it was before), I  
can’t display back the date entered by the user.

Remi

Rick wrote:

> I’m not sure about that “should be 31 April” since every April I’ve  
> ever experienced has only had 30 days. Your first statement “it  
> converts it for 1st may” actually seems to be correct behavior if  
> you’re riding on time’s arrow.
> 
> Rick
> 
> On Oct 31, 5:44ï¿½am, Rï¿½mi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rgagnon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@rgagnon](https://www.ruby-forum.com/u/rgagnon)\
**Post date:** [November 27, 2008, 4:07am UTC](https://www.ruby-forum.com/t/date-select-vs-wrong-date-weird-behavior/152232/4 "2008-11-27T04:07:21Z")

</div>

Remi,

Sorry it’s taken me so long to get back to you, I lost the thread…

I think what you’re looking for is the callback from  
ActiveRecord::Callbacks – before\_save

Rick

On Nov 1, 4:31 am, Rémi Gagnon [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
