[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ruby datetime to mysql

peter

2/28/2007 2:13:00 PM

I'm missing the boat on datetime. I'm trying to convert Ruby datetime to
be compatible with mysql. I'm not getting any errors but the results
always end up 0000-00-00-0000

I think it may have to do with the mysql requirement for 2 digit month
and hours or the seconds. I'm not sure. When I output my conversion to
my browser the output looks correct.

Can someone shed some light on how to do this.

Thanks


7 Answers

Tim Becker

2/28/2007 2:31:00 PM

0

> I'm missing the boat on datetime. I'm trying to convert Ruby datetime to
> be compatible with mysql. I'm not getting any errors but the results
> always end up 0000-00-00-0000

I don't believe you should need to do any conversion, Ruby's date types
should work as parameters to prepared statements and date fields
returned by selects shouldn't need conversions, either. How are you
connecting to mysql, and what problems are you having? It would help
if you posted an example.

-Tim

peter

2/28/2007 4:34:00 PM

0

Hi Tim
I don't have access to my code at the moment but here is the situation.
I have a simple counter on a web page that updates a customer record 0n
every visit. I can use the mysql built in timestamp however I have
another script that runs daily at midnight which of course updates the
timestamp on all records. So I need to add a datetime string to my
update with a date that mysql understands.

I'm new to Ruby scripting so time and datetime are a bit daunting.

Thanks,
Peter


On Wed, 2007-28-02 at 23:31 +0900, Tim Becker wrote:
> > I'm missing the boat on datetime. I'm trying to convert Ruby datetime to
> > be compatible with mysql. I'm not getting any errors but the results
> > always end up 0000-00-00-0000
>
> I don't believe you should need to do any conversion, Ruby's date types
> should work as parameters to prepared statements and date fields
> returned by selects shouldn't need conversions, either. How are you
> connecting to mysql, and what problems are you having? It would help
> if you posted an example.
>
> -Tim
>
>


Tim Becker

2/28/2007 5:00:00 PM

0

> I can use the mysql built in timestamp however I have
> another script that runs daily at midnight which of course updates the
> timestamp on all records. So I need to add a datetime string to my
> update with a date that mysql understands.

Assuming their both ruby scripts, I'm not sure I understand why one
would understand ruby time objects, but not the other.

I think to diagnose this further, we really just need to look at how
you're implementing this, what error messages you're getting, how
you're accessing mysql...

Cheers,
-tim

peter

2/28/2007 5:56:00 PM

0

Hi Again

The one script is eruby index.rhtml the other is not ruby and it does
not use a date or time it simply resets the users quota which also
unfortunately updates the time stamp.

I need to make a string that {#date} is the format that mysql uses,

This is from memory. I connect via dbi to a remote db server on the lan.

dbh.do("UPDATE member SET counter = counter + 1, ip =
'#{ENV['REMOTE_ADDR']}', datetime ='{#date}' WHERE username =
'#{ENV['REMOTE_USER']}'")
end

Peter

On Thu, 2007-01-03 at 02:00 +0900, Tim Becker wrote:
> > I can use the mysql built in timestamp however I have
> > another script that runs daily at midnight which of course updates the
> > timestamp on all records. So I need to add a datetime string to my
> > update with a date that mysql understands.
>
> Assuming their both ruby scripts, I'm not sure I understand why one
> would understand ruby time objects, but not the other.
>
> I think to diagnose this further, we really just need to look at how
> you're implementing this, what error messages you're getting, how
> you're accessing mysql...
>
> Cheers,
> -tim
>
>


Gavin Kistner

2/28/2007 6:00:00 PM

0

On Feb 28, 10:55 am, peter <r...@iwebsl.com> wrote:
> I need to make a string that {#date} is the format that mysql uses,

See the (confusingly-tersely-named) Time#strftime method. It will let
you create whatever format you want. You can even wrap it in your own
method, like:

class Time
def as_mysql
strftime "..."
end
end

Tim Hunter

2/28/2007 6:19:00 PM

0

Gavin Kistner wrote:
> See the (confusingly-tersely-named) Time#strftime method. It will let

strftime is named after the function in the Standard C library. It
creates a _str_ing by _f_ormatting a _t_ime value.

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

dblack

2/28/2007 6:59:00 PM

0