I'm getting back to playing with the ruby "mysql" gem. I'm more used
to rails where a lot of typing issues are magically taken care of.
But now I'm running into this. I do essentially:
db = Mysql::real_connect(blah blah)
sql = "a select query of some sort"
result = db.query(sql)
result.each_hash do |key, value|
do stuff with results here...
end
My problem is that for mysql DateTime fields, the value ends up a
string that looks like
"2010-08-20 00:00:00"
But I want to do things like:
if (value < Time.now)....
My question is, what is the accepted/best-practice way to deal with
this? I can cobble up a strftime string to convert a ruby Time to a
mysql string and let the comparison just be a string compare:
if (value < Time.now.strftime("%Y-%m-%d %H:%M:%S")....
But is that really the best way? Feels a little clunky somehow and
something bothers me about doing a raw string compare, but it's still
a one-liner (and I could hide it in a helper function or add it to the
Time class even) so maybe I should just accept it. :-)
Or maybe "Mysql::Result#each_hash" isn't the way to go?
Thanks...
-glenn
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby