Forum: Ruby on Rails How do you Convert a Time or Date to SQL formatted date?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris R. (Guest)
on 2006-05-09 15:34
I am executing some arbitrary SQL in which i need to convert a date/time
object into an sql formatted string.  Is there a simple way to do this
in rails?

Thanks
Chris
Jean-François (Guest)
on 2006-05-09 16:16
(Received via mailing list)
Hello Chris,

> I am executing some arbitrary SQL in which i need to convert a
> date/time object into an sql formatted string.  Is there a simple
> way to do this in rails?

Try : my_date.to_s(:db)

   -- Jean-François.
Sergio L. (Guest)
on 2006-05-09 21:22
Chris R. wrote:
> I am executing some arbitrary SQL in which i need to convert a date/time
> object into an sql formatted string.  Is there a simple way to do this
> in rails?
>
> Thanks
> Chris

try to do this
date_you_want =
"'"+dateTimeVar["year"]+'-'+dateTimeVar["month"]+'-'+dateTimeVar["day"]+"'"

and then use it in the sentence.
This topic is locked and can not be replied to.