4

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.

Community
  • 1
  • 1
PressingOnAlways
  • 11,948
  • 6
  • 32
  • 59

1 Answers1

9

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')
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Anthony Bobsin
  • 168
  • 1
  • 8