What is the best Date format for working with dates in ruby & mysql?
I have a recurring task that once complete I want to update the db to
reflect the next time to do it.
“2006-11-30” as a string ends up being just “2006”.
tnx in advance.
What is the best Date format for working with dates in ruby & mysql?
I have a recurring task that once complete I want to update the db to
reflect the next time to do it.
“2006-11-30” as a string ends up being just “2006”.
tnx in advance.
Comfort E. wrote:
What is the best Date format for working with dates in ruby & mysql?
As to MySQL, you really need to stick to a strict date format of
yyyy-mm-dd.
This is MySQL’s date format when shown in plain text.
I have a recurring task that once complete I want to update the db to
reflect the next time to do it.“2006-11-30” as a string ends up being just “2006”.
This didn’t happen by magic, you created it with some code. If you show
us
the code, we will show you the magic.
Comfort E. wrote:
p date
dbh = Mysql.real_connect(“localhost”, “xxx”, “xxxx”, “xxxxx”)
chg = dbh.query(“UPDATE sites set updated=’#{date}’ where
url=’#{url}’”)
Not sure why exending Date doesn’t work (at least in irb), but I believe
you
want to be defining the method ‘now’ (not Date.now??)
As an alternate way to do this you could try
$ irb
irb(main):001:0> date = Time.now.strftime(’%Y-%m-%d’)
=> “2006-12-05”
irb(main):002:0>
hth,
Vance
Paul L. wrote:
Comfort E. wrote:
What is the best Date format for working with dates in ruby & mysql?
As to MySQL, you really need to stick to a strict date format of
yyyy-mm-dd.
This is MySQL’s date format when shown in plain text.I have a recurring task that once complete I want to update the db to
reflect the next time to do it.“2006-11-30” as a string ends up being just “2006”.
This didn’t happen by magic, you created it with some code. If you show
us
the code, we will show you the magic.
class Date
def Date.now
return Date.jd(DateTime.now.jd)
end
end
url =‘http://xxx.com’
begin
date = Date.now.to_s
p date
dbh = Mysql.real_connect(“localhost”, “xxx”, “xxxx”, “xxxxx”)
chg = dbh.query(“UPDATE sites set updated=‘#{date}’ where
url=‘#{url}’”)
Vance A Heron wrote:
Comfort E. wrote:
p date
dbh = Mysql.real_connect(“localhost”, “xxx”, “xxxx”, “xxxxx”)
chg = dbh.query(“UPDATE sites set updated=’#{date}’ where
url=’#{url}’”)Not sure why exending Date doesn’t work (at least in irb), but I believe
you
want to be defining the method ‘now’ (not Date.now??)As an alternate way to do this you could try
$ irb
irb(main):001:0> date = Time.now.strftime(’%Y-%m-%d’)
=> “2006-12-05”
irb(main):002:0>
Hmm
Sorry I meant to write back… the above code works when you setup your
mysql tables properly for accepting dates.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs