Hey everyone

i am trying to subtract two different times.i am getting right
when i have two fixed times.
here is my code


def hour_min(last,first)

difference = last - first
seconds = difference % 60
difference = (difference - seconds) / 60
minutes = difference % 60
difference = (difference - minutes) / 60
hours = difference % 24

return hours,minutes

end
if last =9:30 PM and first = 10:52 i get after subtraction 10 hours : 38
mins but the problem is with Time.now
if last = Time.now and first = 10:30 am it is give improper output



this is my view
<% hour_min = hour_min(Time.now.to_i,cin.first.to_i)%>
<%="#{hour_min[0]}Hour : #{hour_min[1]}Min"%>

My problem is if i have two fixed timings i am getting correct but when i
have to calculate with Time.now i am getting wrong answer can any one help
me out



Cheers


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/C56WKFvIvzEJ.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 12 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedAug 28, '12 at 2:19p
activeAug 29, '12 at 11:14a
posts12
users3
websiterubyonrails.org
irc#RubyOnRails

3 users in discussion

Keerthi: 6 posts Colin Law: 4 posts Swati Verma: 2 posts

People

Translate

site design / logo © 2021 Grokbase