# AM/PM select

**URL:** <https://www.ruby-forum.com/t/am-pm-select/95657>\
**Category:** Rails\
**Created:** [June 8, 2006, 10:07am UTC](https://www.ruby-forum.com/t/am-pm-select/95657 "2006-06-08T10:07:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [June 8, 2006, 10:07am UTC](https://www.ruby-forum.com/t/am-pm-select/95657/1 "2006-06-08T10:07:01Z")

</div>

I have a customer that has a request that the select\_datetime fields  
have AM/PM selectors instead of 24 hour time.  
The rails time and datetime selects seem to only support 24 hour time.  
I can’t seem to find any information on this. i was wondering if  
there is already a solution out there, or will i have to roll my own?

Sean W.  
master nerd of  
i heart squares, inc.

3711 N. Ravenswood Ave. #147 Chicago, IL 60613  
[http://www.iheartsquares.com](http://www.iheartsquares.com)

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [June 8, 2006, 11:03am UTC](https://www.ruby-forum.com/t/am-pm-select/95657/2 "2006-06-08T11:03:08Z")

</div>

Sean W. wrote:

> I have a customer that has a request that the select\_datetime fields  
> have AM/PM selectors instead of 24 hour time.  
> The rails time and datetime selects seem to only support 24 hour time.  
> I can’t seem to find any information on this. i was wondering if  
> there is already a solution out there, or will i have to roll my own?
> 
> Sean W.  
> master nerd of  
> i heart squares, inc.
> 
> 3711 N. Ravenswood Ave. #147 Chicago, IL 60613  
> [http://www.iheartsquares.com](http://www.iheartsquares.com)

there is already solution out there… and dont need much coding also…  
cos this is only a formatting question…

using the strftime method would solve the trick!  
options to use are just like the usual sql commands…

eg.  
my\_date.strftime(“%Y-%m-%d–%H:%M”) will generate 2006-06-09–17:30  
my\_date.strftime(“%Y-%m-%d–%I:%M%p”) will generate 2006-06-09–5:30PM

hope this helps!

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [June 8, 2006, 12:44pm UTC](https://www.ruby-forum.com/t/am-pm-select/95657/3 "2006-06-08T12:44:17Z")

</div>

that’s all fine if it’s just the var my\_date you’re trying to format,  
but how would you go about modifying the datetime\_select tag?

\<%= datetime\_select ‘bug’, ‘added\_at’ %\>

I can’t get it to work with .strftime in there…

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [June 8, 2006, 1:43pm UTC](https://www.ruby-forum.com/t/am-pm-select/95657/4 "2006-06-08T13:43:29Z")

</div>

On 6/8/06, Sean W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a customer that has a request that the select\_datetime fields have  
> AM/PM selectors instead of 24 hour time.

Here’s a solution I whipped up for a project a while back. Might not  
be the best solution, but it did the trick.

[http://www.atlrug.org/atlrug/show/12HourHelper](http://www.atlrug.org/atlrug/show/12HourHelper)

-eric

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [June 8, 2006, 10:35pm UTC](https://www.ruby-forum.com/t/am-pm-select/95657/5 "2006-06-08T22:35:59Z")

</div>

Eric W. wrote:

> On 6/8/06, Sean W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I have a customer that has a request that the select\_datetime fields have  
> > AM/PM selectors instead of 24 hour time.
> 
> Here’s a solution I whipped up for a project a while back. Might not  
> be the best solution, but it did the trick.
> 
> [http://www.atlrug.org/atlrug/show/12HourHelper](http://www.atlrug.org/atlrug/show/12HourHelper)

Ahhh! Fantastic. And this is a lot better than i was expecting. Nice  
solution to put it all into a single Drop. I thought about it being a  
mess to have AM/PM selector on the side.

I’ve posted this link into my [del.icio.us](http://del.icio.us)

---

<div class="post-metadata">

**Author:** ![seanwarburton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@seanwarburton](https://www.ruby-forum.com/u/seanwarburton)\
**Post date:** [June 8, 2006, 10:44pm UTC](https://www.ruby-forum.com/t/am-pm-select/95657/6 "2006-06-08T22:44:41Z")

</div>

I also made something similar, with an am/pm dropdown and model support:

[http://www.happyfreelancer.com/?p=10](http://www.happyfreelancer.com/?p=10)

This is also supposed to be very good:

[http://wiki.rubyonrails.org/rails/pages/FlexTimes+Plugin](http://wiki.rubyonrails.org/rails/pages/FlexTimes+Plugin)

Hope this helps!
