Noob DateTime question

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

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

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:

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 P.

http://www.billpratt.net
[email protected]