Quantcast
Viewing all articles
Browse latest Browse all 10

Converting Ruby time function into a database friendly format to compare time.

Use to_s(:db) to convert Ruby time function into a database friendly format to compare time.

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.

The post Converting Ruby time function into a database friendly format to compare time. appeared first on Code Beer Startups.


Viewing all articles
Browse latest Browse all 10

Trending Articles