# How to get just hour and minute?

**URL:** <https://www.ruby-forum.com/t/how-to-get-just-hour-and-minute/163026>\
**Category:** Ruby\
**Created:** [March 16, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/how-to-get-just-hour-and-minute/163026 "2009-03-16T20:25:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 16, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/how-to-get-just-hour-and-minute/163026/1 "2009-03-16T20:25:43Z")

</div>

I have a Ruby project with a User object that consists of various  
fields (attributes). Two of these are preferredStart and preferredEnd  
and were configured with the “… script/generate scaffold …”  
command to have type “time”. When I visit the resulting “New User”  
page, the input for those two fields has date and time. In other  
words, the user could select a month, date and year in addition to  
hour, minute and second for preferredStart and preferredEnd. The  
relevent code from the view/new\_user.html.erb is:

\<%= f.label :preferredStart %\>  
 \<%= f.datetime\_select :preferredStart %\>

\<%= f.label :preferredEnd %\>  
 \<%= f.datetime\_select :preferredEnd %\>

Is there a way to limit the input selection to simply hour and  
minute? I tried, for instance:

\<%= f.datetime\_select :preferredStart, prompt =\> {:hour =\>  
true, :minute =\> true} %\>

That did not have the intended effect, though.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 16, 2009, 8:32pm UTC](https://www.ruby-forum.com/t/how-to-get-just-hour-and-minute/163026/2 "2009-03-16T20:32:45Z")

</div>

Have a look at time\_select.

[http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M002094&name=time\_select](http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M002094&name=time_select)

Regards,  
Craig

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 16, 2009, 8:45pm UTC](https://www.ruby-forum.com/t/how-to-get-just-hour-and-minute/163026/3 "2009-03-16T20:45:08Z")

</div>

By the way, you should ask Rails questions here:

[http://groups.google.com/group/rubyonrails-talk](http://groups.google.com/group/rubyonrails-talk)

Regards,  
Craig

On Mon, Mar 16, 2009 at 3:29 PM, Craig D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 16, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/how-to-get-just-hour-and-minute/163026/4 "2009-03-16T20:46:19Z")

</div>

On Mar 16, 3:29 pm, Craig D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Note: parts of this message were removed to make it a legal post.]

Had I included content that was not ‘legal’? Apologies to all if I  
had.

> Have a look at time\_select.
> 
> [http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M002094&na](http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M002094&na)…

That did it, thank you for the quick reply and the nudge in the right  
direction. As you probably have guessed, I’m way down on the left side  
of the learning curve. Thanks!

AG
