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.
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris Richards (chris)
on 2006-05-09 13: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
13ea48f056b19349027d2f4a6921a46a?d=identicon&s=25 Jean-François (Guest)
on 2006-05-09 14: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.
468f4fd55bf0dac4813dc92f07b42fca?d=identicon&s=25 Sergio Luis (malvadomx)
on 2006-05-09 19:22
Chris Richards 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.