According to "Ruby datetime suitable for mysql comparison", I should be able to do:
Time.now.to_s(:db)
This doesn't appear to be valid anymore. I get:
irb(main):001:0> Time.now.to_s(:db)
ArgumentError: wrong number of arguments (1 for 0)
from (irb):1:in `to_s'
from (irb):1
from C:/Ruby22/bin/irb:11:in `<main>'
Does this functionality still exist or do I have to manually format the date and time to fit MySQL format?
I'm using ruby 2.2.2.
Time#to_s doesn't accept arguments in Ruby. If you're using Rails, ActiveSupport::TimeWithZone supplies the to_s method you were referring to.
To get this format in Ruby without ActiveSupport you can use:
Time.now.strftime('%Y-%m-%d %H:%M:%S')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With