E
E
eldar_web2015-09-08 16:53:38
Ruby on Rails
eldar_web, 2015-09-08 16:53:38

How to find the difference in hours between two times in Ruby?

For example, there are two tenses:

old_date = Tue, 08 Sep 2015 14:52:18 MSK +03:00
new_date = Tue, 08 Sep 2015 16:52:18 MSK +03:00

Today's date, but the time (in hours) is different. So I want to determine the difference in hours from these dates. How to implement it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
eldar_web, 2015-09-08
@eldar_web

old_date = Time.parse('Tue, 08 Sep 2015 14:52:18 MSK +03:00') %>
today_date = Time.parse('Tue, 08 Sep 2015 17:52:18 MSK +03:00') %>
((today_date - old_date).to_i / 60 ) / 60 # 3

T
TyzhSysAdmin, 2015-09-08
@POS_troi

Everything is the same as before How to find the difference in hours in two dates in RUBY ???
Finally read the documentation

A
Alexey, 2015-09-08
@ringo

yes, everything is also
only variables must be of class Time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question