views:

63

answers:

1

Hello!

I have a Database column with the syntax "0000-00-00 00:00:00". In PHP I would do date('Y-m-d H:i:s');

In Ruby, I do

require 'date'
now = DateTime::now()
puts "#{now.year()}-#{now.mon()}-#{now.mday()} #{now.hour()}:#{now.min()}:#{now.sec()}"

The result is: "2010-1-5 10:16:4" That's not okay. How could I create a "timestring" with the format "0000-00-00 00:00:00"?

Thanks a lot in advance & Best Regards

+4  A: 

You can format the dates like in PHP thanks to the built-in Time class, see documentation there.

This would give for your case :

t = Time.now
puts t.strftime("%Y-%m-%d %H:%M:%S")
subtenante
thanks a lot for your help!
Tim