From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Date and time helpers

Date and time helpers - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Date and time helpers

- [Instructor] Ruby on Rails offers us many helpers to assist with date and time calculations and formatting. These methods aren't exactly helper methods, like the other ones we've been looking at, because these methods are available throughout Rails, not just in our view templates. These methods are additions that Rails makes to Ruby's core classes. Because they're available anywhere, you can open up a Rails console to try them out. Let's get an overview of what methods are available. First, there's DateTime calculations using integers. We just use an integer and then after it we put a time period name like second, minute, hour, day, week, month, year, and the plural form of all of those. This allows us to work with time by doing simple addition and using English words. So, for example, time.now plus 30.days minus 23.minutes. Now, 30.days is actually being converted into a certain number of seconds, 23.minutes is being converted into a certain number of seconds, and those are being…

Contents