Rails DateTime.now without Time

Mike picture Mike · Nov 19, 2011 · Viewed 116.1k times · Source

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

Answer

Igor Kapkov picture Igor Kapkov · Nov 19, 2011

You can use one of the following:

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