Skip to content

Instantly share code, notes, and snippets.

@francois-blanchard
Last active January 13, 2016 14:15
Show Gist options
  • Save francois-blanchard/9e18b80eebe70856acdd to your computer and use it in GitHub Desktop.
Save francois-blanchard/9e18b80eebe70856acdd to your computer and use it in GitHub Desktop.
DateTime and Time Rails Helpers

DateTime and Time Rails Helpers

Time.current.beginning_of_day
=> Tue, 12 Jan 2016 00:00:00 CET +01:00
Time.current.beginning_of_hour
=> Tue, 12 Jan 2016 18:00:00 CET +01:00
Time.current.beginning_of_minute
=> Tue, 12 Jan 2016 18:12:00 CET +01:00
Time.current.end_of_day
=> Tue, 12 Jan 2016 23:59:59 CET +01:00
Time.current.end_of_hour
=> Tue, 12 Jan 2016 18:59:59 CET +01:00
Time.current.end_of_minute
=> Tue, 12 Jan 2016 18:15:59 CET +01:00

Use case

date = DateTime.current
Data.where(created_at: date.beginning_of_day..date.end_of_day)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment