dates, scheduling tasks, mysql

C

Comfort Eagle

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

Comfort Eagle

Paul said:
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.


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}'")
 
V

Vance A Heron

Comfort said:
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}'")
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
 
C

Comfort Eagle

Vance said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top