[Rails] Converting time retrieved from MySQL (part 2)
Ara.T.Howard
Ara.T.Howard at noaa.gov
Wed Mar 9 16:40:59 GMT 2005
On Wed, 9 Mar 2005, Nathan Wright wrote:
> Sorry for taking so long to check out everyone's suggestions, but here's what
> I've found out:
>
> I'm accessing the time from the MySQL database with this query
> "comment.created_on".
>
> By checking the class of this query with "comment.created_on.class" I've
> found out that this is, in fact, returning a Time object. (neat trick by the
> way!)
>
> When I attempt to apply any "time" methods to this object (for instance,
> "comment.created_on.strftime_("%A")") I get the following error:
what's with the underscore?
> undefined method `strftime' for nil:NilClass
you can also render this (another neat trick):
comment.created_on.methods.inspect
or even
comment.created_on.class.instance_methods.inspect
if you see 'strftime' in there you are doing something strange. of course you
can always ask the object too by rendering the output of
comment.created_on.repspond_to? 'strftime'
>
> Does anyone have an idea of what I'm doing wrong (likely), or is this a
> problem with Rails (unlikely)?
>
>
> ---------------------------
> Original Problem (If you're joining us late in the game):
> ---------------------------
> I'm having a problem converting a date retrieved from my MySQL database and
> I'm hoping someone can help.
>
> MySQL stores the date/time as this:
>
> 2005-03-08 17:00:34.0
>
> and according to my Pickaxe book Ruby stores times as "the number of seconds
> and microseconds since [...] January 1, 1970". All well and
> good. Unfortunately, RoR is converting my date to this:
>
> Tue Mar 08 17:00:34 MST 2005
>
> which, as far as I can tell, is as string representation of the date; as
> such, I can't perform any date operations on it (strftime, etc).
>
> My question has two parts:
> 1) Can some sort of date operation be brought to bear on RoR's internal date
> format to make it compatible with standard Ruby date
> operations?
> 2) If not, is there some way to turn off RoR's parsing of the date returned
> from the MySQL query?
>
>
> --
> Nathan Wright
> http://www.brandalism.com
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
More information about the Rails
mailing list