I’m trying to build options for a select box that would output a range
of dates between two dates that I specified. For example, if my two
dates (both coming from datetime fields in a MySQL database) were:
Ruby DATE class implements the “upto” method, so assuming you can
massage @first_date and @second_date as DATE objects, you should be able
to do something like this (in your view):
<% @first_date.upto(@second_date) do |date| %>
(option value="<% date.to_s %>")<% date.to_s %>(/option)
<% end %>
Of course, you’ll need to massage the output of date.to_s to get the
formats that you want - strftime method does this for Time objects, not
sure if it applies for Date objects.
c.
Sean wrote:
I’m trying to build options for a select box that would output a range
of dates between two dates that I specified. For example, if my two
dates (both coming from datetime fields in a MySQL database) were:
Again, you’ll want to get the formats of the date.to_s correct in the
first line of code. The first date.to_s is what is used for the display,
the second is what is used for the value.
c.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.