Hi,
I have a database column defined as datetime.
When i display <%= orders.orderdate %> in the view i get:
Thu Aug 16 12:22:53 +0100 2007
Which is as expected. What I would like though is to just display the
time portion of the column.
I think i need to convert the orders.orderdate to a time so i can do
something like: time.strftime(''%H:%M'') but i''m not
sure!
Its such a simple thing, but its taking me ages to work out!
Thanks,
Mike
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi, you can define an instance method on the Order model class that returns
the time portion of the datetime field. For example,
def get_time
self.orderdate.strftime(''%H:%M'')
end
Now, self is referencing the current Order instance.
Good luck,
-Conrad
On 8/16/07, Mike Rowlands
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Hi,
>
> I have a database column defined as datetime.
> When i display <%= orders.orderdate %> in the view i get:
>
> Thu Aug 16 12:22:53 +0100 2007
>
> Which is as expected. What I would like though is to just display the
> time portion of the column.
>
> I think i need to convert the orders.orderdate to a time so i can do
> something like: time.strftime(''%H:%M'') but i''m
not sure!
>
> Its such a simple thing, but its taking me ages to work out!
>
> Thanks,
>
> Mike
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
That would work, and you can also use the hour, min, sec methods in the time class if you need them separately. http://www.ruby-doc.org/core/classes/Time.html Mike Rowlands wrote:> Hi, > > I have a database column defined as datetime. > When i display <%= orders.orderdate %> in the view i get: > > Thu Aug 16 12:22:53 +0100 2007 > > Which is as expected. What I would like though is to just display the > time portion of the column. > > I think i need to convert the orders.orderdate to a time so i can do > something like: time.strftime(''%H:%M'') but i''m not sure! > > Its such a simple thing, but its taking me ages to work out! > > Thanks, > > Mike >-- Sincerely, William Pratt http://www.billpratt.net billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---