Reputation: 533
I am working on datediff in Ruby. I am making a query to the datebase and I am getting createdDate result in this format:
2016-04-10T19:54:44.000Z.
My task is to check whether difference of createdDate and current time is greater than 30 mins or not. When I create current time in UTC format :
utctime = Time.now.utc
I am getting result like this ;
2016-04-10 19:59:57 UTC
My question is: the createdDate that I get from the database has T and .000Z. in it, it is any easy way to compare them to find 30 mins difference.
Because right now, I am planning to change:
T with space and .000Z. with UTC to make them in the same format.
Upvotes: 1
Views: 115
Reputation: 13477
You can use standard -
operator for Time
objects:
time_diff = Time.parse('2016-04-10T19:54:44.000Z') - utctime #in seconds
result = (time_diff / 60).abs > 30 #true or false
Upvotes: 2