# HELP FOR SEPARATING TIME

**URL:** <https://discuss.rubyonrails.org/t/help-for-separating-time/46487>\
**Category:** rubyonrails-talk\
**Created:** [September 30, 2009, 9:45am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487 "2009-09-30T09:45:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [September 30, 2009, 9:45am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/1 "2009-09-30T09:45:03Z")

</div>

hi.. i m using date picker like below \<%= calendar\_date\_select\_tag "e\_date", Date.today, :popup =\> :force ,:time =\> true %\>

when i submit the form i get parameter like below

September 30, 2009 03:08 PM

i want to cut the time from it...

tat is 03:08 PM and September 30, 2009 has to be separated..

any helps for this...

Thanks for taking time to help

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [September 30, 2009, 9:58am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/2 "2009-09-30T09:58:04Z")

</div>

just remove :time option from the syntax..

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [September 30, 2009, 10:23am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/3 "2009-09-30T10:23:59Z")

</div>

You can separate date and time by...

first you need to convert into date format datetime=params[:e\_date] datetime=datetime.to\_date date = date.strftime('%Y-%m-%d')"

I hope this helps u...

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [September 30, 2009, 10:29am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/4 "2009-09-30T10:29:05Z")

</div>

Hi Newb newb

use @date.strftime("%B %d, %Y")

to display only date no time. and in table insert September 30, 2009 03:08 PM

Newb Newb wrote:

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [September 30, 2009, 10:35am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/5 "2009-09-30T10:35:20Z")

</div>

> You can separate date and time by...
> 
> first you need to convert into date format datetime=params[:e\_date] datetime=datetime.to\_date

I think there is no need to convert it to a Date, just use strftime on the DateTime object to show just the date portion.

Colin

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [September 30, 2009, 10:41am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/6 "2009-09-30T10:41:25Z")

</div>

Hi Colin

Conversion is required because passing value is string not datetime ...

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [September 30, 2009, 10:51am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/7 "2009-09-30T10:51:41Z")

</div>

Yes you are right, I was thinking datetime\_select was being used to read into a DateTime object.

Colin

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [September 30, 2009, 12:25pm UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/8 "2009-09-30T12:25:23Z")

</div>

Newb Newb wrote: [...]

> hi all.. i want to ask one more help...
> 
> d0\_time = d0.strftime("%I:%M %p") d1\_time = d1.strftime("%I:%M %p")
> 
> 12:00 am 07:00 pm i get two times here.i ll take the above times as from and to. i have time as field into my table.it stores like 01:17:56 am.

Are you storing the time as a string in the DB? If so, don't. Store times as time or datetime.

> i want to fetch the records which is between the above two times .. how can i implement the query

SELECT \* FROM table WHERE hour(time) BETWEEN 0 and 19

> pls suggest me

Best,

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 1, 2009, 2:45am UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/9 "2009-10-01T02:45:16Z")

</div>

Marnen Laibow-Koser wrote:

> Newb Newb wrote: [...]
> 
> > hi all.. i want to ask one more help...
> > 
> > d0\_time = d0.strftime("%I:%M %p") d1\_time = d1.strftime("%I:%M %p")
> > 
> > 12:00 am 07:00 pm i get two times here.i ll take the above times as from and to. i have time as field into my table.it stores like 01:17:56 am.
> 
> Are you storing the time as a string in the DB? If so, don't. Store times as time or datetime.
> 
> > i want to fetch the records which is between the above two times .. how can i implement the query
> 
> SELECT \* FROM table WHERE hour(time) BETWEEN 0 and 19
> 
> > pls suggest me
> 
> Best, -- Marnen Laibow-Koser [http://www.marnen.org](http://www.marnen.org) marnen@marnen.org

hi.. i m using date picker like below \<%= calendar\_date\_select\_tag "e\_date", Date.today, :popup =\> :force ,:time =\> true %\>

is it possible to disable the dates ... i want to able to select only time... is it possible... thanks in advance

---

<div class="post-metadata">

**Author:** ![Rick3](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@Rick3](https://discuss.rubyonrails.org/u/Rick3)\
**Post date:** [October 1, 2009, 3:59pm UTC](https://discuss.rubyonrails.org/t/help-for-separating-time/46487/10 "2009-10-01T15:59:31Z")

</div>

Model.find(:all, :conditions =\> {:time\_field =\> (from..to)})
