FAQ
@colin if i have two timings9:30 PM and 10:52 i got correct output here it
is 10 hours : 38mins
and if i give Time.now as one input and 10:30 AM as another input i got 2
hours : mins

i dont think it is timezone issue because if there are two fixed inputs and
if i subtract them with my code i get the correct output the only issue is
with Time.now as a input i guess. i wanna calculate the working hours with
mins of an employee. As i explained before if the employee checkin and
checkout time is there i can able to calculate it and if i wanna show right
from his checkin until he checkout every min of his working hours and mins
i have to go for Time.now as another input.
On Tue, Aug 28, 2012 at 8:05 PM, Colin Law wrote:
On 28 August 2012 15:18, Khan wrote:
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)%>
You should not need to call to_i, just pass in the times, the
difference of two times is the difference in seconds.
If i don't call with to_i the output will be with decimal(i.e., 3.o hours )
to convert them i went with 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
Have a look at the Rails Guide on debugging which will show you
techniques that can be used to debug the code. I would start just by
running the console (rails c) and try calling your method with various
values and see what happens. You can use puts in the method to print
intermediate results and see what is happening.

What results are you getting? Is it a number of hours out? If so
then I guess it is a time zone issue.

Colin

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

## Related Discussions

Discussion Navigation
 view thread | post posts ‹ prev | 3 of 12 | next ›
Discussion Overview
 group rubyonrails-talk categories rubyonrails posted Aug 28, '12 at 2:19p active Aug 29, '12 at 11:14a posts 12 users 3 website rubyonrails.org irc #RubyOnRails

### 3 users in discussion

Content

People

Support

Translate

site design / logo © 2021 Grokbase