How do you Convert a Time or Date to SQL formatted date?


#1

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


#2

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.


#3

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.