[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

dates, scheduling tasks, mysql

Comfort Eagle

11/30/2006 8:02:00 PM

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.

--
Posted via http://www.ruby-....

4 Answers

Paul Lutus

11/30/2006 8:47:00 PM

0

Comfort Eagle 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.

--
Paul Lutus
http://www.ara...

Comfort Eagle

11/30/2006 9:23:00 PM

0

Paul Lutus wrote:
> Comfort Eagle 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://xx...
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}'")

--
Posted via http://www.ruby-....

Vance A Heron

12/5/2006 10:17:00 PM

0

Comfort Eagle wrote:
> Paul Lutus wrote:
>
>> Comfort Eagle 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://xx...
> 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


Comfort Eagle

12/5/2006 11:01:00 PM

0

Vance A Heron wrote:
> Comfort Eagle 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.

--
Posted via http://www.ruby-....