# How to have default date for date\_select

**URL:** <https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718>\
**Category:** Rails\
**Created:** [January 11, 2007, 9:28pm UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718 "2007-01-11T21:28:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [January 11, 2007, 9:28pm UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718/1 "2007-01-11T21:28:24Z")

</div>

lo there all,  
i want to have a date\_select heper default to the year 2006, but cant  
seem to find out how to pull it off.  
any takers ?

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [January 12, 2007, 4:26am UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718/2 "2007-01-12T04:26:48Z")

</div>

I think the fields just show the current value of the object.  
Have you tried something like this?

\<%= model.date = Date.today; date\_select :model, :date %\>

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [January 12, 2007, 11:11am UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718/3 "2007-01-12T11:11:45Z")

</div>

date\_select will show the current value of the object.  
you can set a default value of this object in controller.  
@object.date= ‘2006-01-01’

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [January 12, 2007, 1:41pm UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718/4 "2007-01-12T13:41:50Z")

</div>

is it possible to have not a date by default but day in the days field,  
month in the months field and year in the years field?  
does select\_date have an option to do this?

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [January 14, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718/5 "2007-01-14T14:28:43Z")

</div>

jil wrote:

> is it possible to have not a date by default but day in the days field,  
> month in the months field and year in the years field?  
> does select\_date have an option to do this?

up

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/how-to-have-default-date-for-date-select/81718/6 "2007-01-19T16:31:25Z")

</div>

On Jan 11, 10:28 pm, Shawn B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> i want to have a date\_select heper default to the year 2006, but cant  
> seem to find out how to pull it off.

Assign the default value you want, in the new action. date\_select()  
will do the right thing with it in the view.

e.g.

def new  
@calendar\_event = CalendarEvent.new :start\_date =\>  
“2006-01-01”.to\_date  
end

Are you sure you want the default year to be 2006, and not the current  
year?

e.g.

def new  
@calendar\_event = CalendarEvent.new :start\_date =\>  
Time.parse(“#{Time.today.year}-01-01”)  
end

Ciao,  
Sheldon.
