Hi In the table I have a field updated_on (type :datetime)..I have to calculate the differnce in hours between that and current time..How can I do that? I tried like for example time1=TimeTable.find(1).updated_on time2=Time.new puts (time1-time2) but it is not working Prints a very large value..Could you please tell me any easier method? Thanks in advance Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-17 08:54 UTC
Re: to calculate differnece between two time variables
On 17 Jun 2008, at 08:59, Sijo Kg wrote:> > Hi > In the table I have a field updated_on (type :datetime)..I have to > calculate the differnce in hours between that and current time..How > can > I do that? > > I tried like for example > time1=TimeTable.find(1).updated_on > time2=Time.new > puts (time1-time2) but it is not working Prints a very large > value..Could you please tell me any easier method? >It is working, but that gives you the difference in seconds. converting it to hours (divide by 3600) should be an easy exercise. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi thanks for your reply..One more question related to this..In my ServiceDeskTicket model i have two fields 1.updted_on 2.service_desk_status_id I have to find out all records with time difference between updated_on and current time > 48 hours and service_desk_status_id=6. Could you please tell me how I can write this? Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-17 09:11 UTC
Re: to calculate differnece between two time variables
On 17 Jun 2008, at 10:04, Sijo Kg wrote:> > Hi > thanks for your reply..One more question related to this..In my > ServiceDeskTicket model i have two fields > 1.updted_on > 2.service_desk_status_id > I have to find out all records with time difference between > updated_on and current time > 48 hours and service_desk_status_id=6. > Could you please tell me how I can write this? >that''s even easier, you just need to find records where updated_on is more than 48 hours ago. Rails even provides some helpers here: 48.hours.ago will evaluate to that time. Fred> Sijo > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi thanks for this information Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi I tried like time_array=ServiceDeskTicket.find :all, :conditions=>["updated_on > ? ",48.hours.ago] puts time_array But actually I have to get 10 records .ie (10 records are updated before 48 hours) but I get the opposite that is 20 Total 30 records in table..Am I missing something?Is the condition wrong? Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-17 09:33 UTC
Re: to calculate differnece between two time variables
On 17 Jun 2008, at 10:30, Sijo Kg wrote:> > Hi > I tried like > time_array=ServiceDeskTicket.find :all, :conditions=>["updated_on > > ? > ",48.hours.ago] > puts time_array > > But actually I have to get 10 records .ie (10 records are > updated > before 48 hours) but I get the opposite that is 20 Total 30 records in > table..Am I missing something?Is the condition wrong?You put > instead of < Fred> > > Sijo > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---