# Dates entered as MM/DD/YY

**URL:** <https://www.ruby-forum.com/t/dates-entered-as-mm-dd-yy/99805>\
**Category:** Rails\
**Created:** [February 1, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/dates-entered-as-mm-dd-yy/99805 "2006-02-01T20:10:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [February 1, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/dates-entered-as-mm-dd-yy/99805/1 "2006-02-01T20:10:45Z")

</div>

I have some forms on my site that use text boxes to enter dates. They  
typically default to today’s date, in the format “MM/DD/YYYY”

However, sometimes a user will erase the box and type in a date, but  
instead of typing 02/01/2006, they’ll type 2/1/06. Once the record is  
created in the mysql database, it reads as ‘0006-02-01’ instead of  
‘2006-02-01.’ Is there an easy way around this, or do I need something  
in my create / update functions to catch and fix this? I have my reasons  
for not using a date-picker control.

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [February 1, 2006, 8:19pm UTC](https://www.ruby-forum.com/t/dates-entered-as-mm-dd-yy/99805/2 "2006-02-01T20:19:48Z")

</div>

Use a before\_save filter and pass your incoming date field to ParseDate  
module to get a standardized date format suitable for your database.

Bob

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [February 2, 2006, 12:02am UTC](https://www.ruby-forum.com/t/dates-entered-as-mm-dd-yy/99805/3 "2006-02-02T00:02:01Z")

</div>

Dylan M. \<dylan@…\> writes:

> I have some forms on my site that use text boxes to enter dates. They  
> typically default to today’s date, in the format “MM/DD/YYYY”

> However, sometimes a user will erase the box and type in a date, but  
> instead of typing 02/01/2006, they’ll type 2/1/06. Once the record is  
> created in the mysql database, it reads as ‘0006-02-01’ instead of  
> ‘2006-02-01.’ Is there an easy way around this, or do I need something  
> in my create / update functions to catch and fix this? I have my reasons  
> for not using a date-picker control.

You can fix the input before saving with:

Date.parse(params[:date], comp=true).to\_s

[http://www.ruby-doc.org/core/classes/Date.html#M001197](http://www.ruby-doc.org/core/classes/Date.html#M001197)
