# Odd Behavior for datetime\_select

**URL:** <https://www.ruby-forum.com/t/odd-behavior-for-datetime-select/148584>\
**Category:** Rails\
**Created:** [September 15, 2008, 9:40am UTC](https://www.ruby-forum.com/t/odd-behavior-for-datetime-select/148584 "2008-09-15T09:40:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maraby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@maraby](https://www.ruby-forum.com/u/maraby)\
**Post date:** [September 15, 2008, 9:40am UTC](https://www.ruby-forum.com/t/odd-behavior-for-datetime-select/148584/1 "2008-09-15T09:40:43Z")

</div>

I’m running into an odd situation where datetime\_select is making the  
hours into minutes and putting nothing in for hours. My database  
table is mysql which looks like:

```
create_table :my_sessions do |t|
  t.integer :user_id
  t.string :ssession_id
  t.date :start_date
  t.time :start_time
  t.time :end_time
  t.string :location
  t.string :title
  t.string :source
  t.boolean :msg_sent

  t.timestamps
end

```

The View is standard scaffold:

# Editing my\_session
\<% form\_for (@my\_session) do |f| %\> 

\<%= f.label :ssession\_id %\>  
 \<%= f.text\_field :ssession\_id %\>

\<%= f.label :start\_date %\>  
 \<%= f.date\_select :start\_date %\>

\<%= f.label :start\_time %\>  
 \<%= f.datetime\_select :start\_time %\>

\<%= f.label :end\_time %\>  
 \<%= f.datetime\_select :end\_time %\>

\<%= f.label :location %\>  
 \<%= f.text\_field :location %\>

\<%= f.label :title %\>  
 \<%= f.text\_field :title %\>

\<%= f.submit "Update" %\>

\<% end %\> \<%= link\_to 'Show', @my\_session %\> | \<%= link\_to 'Back', my\_sessions\_path %\>

My controller is:  
def update  
user = User.find(session[:user\_id])  
@my\_session = MySession.find(params[:id], :conditions =\>  
[“my\_sessions.user\_id = ?”, user.id])

```
respond_to do |format|
  if @my_session.update_attributes(params[:my_session])
    flash[:notice] = 'MySession was successfully updated.'
    format.html { redirect_to(@my_session) }
    format.xml { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml { render :xml => @my_session.errors, :status

```

=\> :unprocessable\_entity }  
end  
end  
end

The model is empty.

Again, if I view my edit page and the time that is returned from the  
database is:  
January 1, 2007, 13:45  
I change it on the form to be:  
January 1, 2007, 12:45  
What gets stored is:  
January 1, 2007, 1:12

When creating a new record the day gets set as the hour, the hour the  
minute and the minute the seconds. Its really odd. Any help would be  
great.

Thanks Matt

---

<div class="post-metadata">

**Author:** ![maraby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@maraby](https://www.ruby-forum.com/u/maraby)\
**Post date:** [September 15, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/odd-behavior-for-datetime-select/148584/2 "2008-09-15T22:45:23Z")

</div>

I’ve done some more playing around with this and it looks like if I  
:include\_seconds true the values update as expected. However, without  
this it always shifts the values one to the right. My guess is that in  
the code for the actionview helper it doesn’t append :00 to the end of  
the time.

Looking at the html generated code there is a new  
my\_session[start\_time(6i)] name thats created. If I don’t have the  
include\_seconds there is no hidden value for this on the page, which is  
what I’m guessing is the cause of the problem.

I’m new to rails, who/how would I go about posting this as a possible  
bug. Is there any other validation I should go about before posting it?

---

<div class="post-metadata">

**Author:** ![maraby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@maraby](https://www.ruby-forum.com/u/maraby)\
**Post date:** [September 16, 2008, 2:51am UTC](https://www.ruby-forum.com/t/odd-behavior-for-datetime-select/148584/3 "2008-09-16T02:51:57Z")

</div>

On Sep 16, 4:45 am, Matt T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m new to rails, who/how would I go about posting this as a possible  
> bug. Is there any other validation I should go about before posting it?
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

What Rails version are you using?
