Ruby datetime suitable for mysql comparison

You can use to_s(:db) to convert into a database friendly format.

Time.now.to_s(:db)

However, be careful if you have a timezone specified in Rails because the time will be stored in UTC in the database. You’ll need to specify that to do proper comparisons.

Time.now.utc.to_s(:db)

You can also use NOW() function in MySQL instead of generating the current time in Ruby.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)