I’d like to write a simple function to say in hours:
How much time has passed since this has been created?
My attempts:
-time = DateTime.now.hour - (self.created_at.hour)
Does anyone know how to do this in Ruby on Rails?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Rails usually uses
Time, notDateTime. Why don’t you doTime.now - self.created_at? Then you can convert from seconds to hours by dividing by 3600.