From the course: Ruby on Rails 6: Controllers and Views

Unlock the full course today

Join today to access over 22,500 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 6: Controllers and Views

Start my 1-month free trial

Date and time helpers

- Ruby on Rails has some really useful helpers. For helping us to work with dates and time. Let's look at a few of them. The first is methods that allow us to make date time calculations using simple integers. To do that there are number of methods we could use. There are second, minute, hour, day, week, month, year and then there's synonyms for all those which just a plural forms. It doesn't matter which one you use second or seconds, it's going to do the exact same thing. One of them just will read better in your code. So the way we would do a calculation is you would call Time.now and that's going to return a Unix timestamp which is the number of seconds since 1970. Now if we want to modify that time, you would normally add seconds to it. So you might be adding some huge number of seconds, thousands and thousands seconds and to calculate that it's not uncommon for us to have to do 60 times 60 times 24 times seven…

Contents