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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…