Ruby-on-rails – Rails DateTime.now without Time

datetimerubyruby-on-rails

I need to use DateTime.now to grab the current date, and "strip off" the time.

For example, this shows what I don't want: DateTime.now => Sat, 19 Nov 2011 18:54:13 UTC +00:00

This shows what I do want: DateTime.now.some_operation => 2011-11-06 00:00:00 UTC

Best Answer

You can use one of the following:

  • DateTime.current.midnight
  • DateTime.current.beginning_of_day
  • DateTime.current.to_date