# Is there a way to get date\_select to "select" another date b

**URL:** <https://www.ruby-forum.com/t/is-there-a-way-to-get-date-select-to-select-another-date-b/108891>\
**Category:** Rails\
**Created:** [July 9, 2007, 3:42am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-get-date-select-to-select-another-date-b/108891 "2007-07-09T03:42:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://www.ruby-forum.com/u/sharon)\
**Post date:** [July 9, 2007, 3:42am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-get-date-select-to-select-another-date-b/108891/1 "2007-07-09T03:42:08Z")

</div>

Is there a way to use date\_select in the form\_for helper and have the  
displayed date in the drop-down list be something besides “today”? I’m  
trying to get it to be “yesterday” without success. I also tried

\<% d = Date.today %\>  
\<% d = d-1 %\>  
\<%= select\_date (date=d) %\>

and that didn’t work either.

Thanks.

Sharon

---

<div class="post-metadata">

**Author:** ![sharon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://www.ruby-forum.com/u/sharon)\
**Post date:** [July 9, 2007, 4:51am UTC](https://www.ruby-forum.com/t/is-there-a-way-to-get-date-select-to-select-another-date-b/108891/2 "2007-07-09T04:51:12Z")

</div>

Sharon,

I assume you’re trying to have a date field default to yesterday in  
the form if it hasn’t already been set by the user? Try setting it to  
yesterday in the controller. So if you have an ActiveRecord object  
called event that includes an attribute called scheduled\_date, do  
something like this in the controller action:

event.scheduled\_date ||= 1.day.ago

Now you should be able to use the form\_for/date\_select and get the  
right result. Alternatively, you could use the select\_date helper…  
should look something like:

select\_date(1.day.ago)

Cheers,  
Ken

---

<div class="post-metadata">

**Author:** ![sharon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/67e7ee/32.png) [@sharon](https://www.ruby-forum.com/u/sharon)\
**Post date:** [July 9, 2007, 11:20pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-get-date-select-to-select-another-date-b/108891/3 "2007-07-09T23:20:56Z")

</div>

Sharon M. wrote:

> Is there a way to use date\_select in the form\_for helper and have the  
> displayed date in the drop-down list be something besides “today”? I’m  
> trying to get it to be “yesterday” without success. I also tried
> 
> \<% d = Date.today %\>  
> \<% d = d-1 %\>  
> \<%= select\_date (date=d) %\>
> 
> and that didn’t work either.

From [api.rubyonrails.org](http://api.rubyonrails.org) you should use

select\_date(d)

The notation select\_date(date = Date.today, options = {}) means - if  
there is no parameter supplied it uses Date.today as first parameter and  
an empty hash as options.

Stefan
