Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 843771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:10:58+00:00 2026-05-15T06:10:58+00:00

I have a feeling someone is going to point me to another question that

  • 0

I have a feeling someone is going to point me to another question that answers this but I’ve been searching with no luck over this simple issue.

I have a Activerecord with a datetime property. It returns as an ActiveSupport:TimeWithZone. I know I can’t compare that to DateTime.now because that doesn’t include a zone so I need to use Time.zone. Makes sense.

What I’m wondering is stylewise is there a “cleaner” way to do this than subtracting and dividing the result by 86400?

Here’s what I do:

((Time.zone.now - myActiveRecord.visit_date)/86400).to_i

Works but seems un-rubyish and I feel like I’m missing something. Should I be casting, comparing or converting some other route or is this really the typical way to do this in rails? Appreciate any tips or a link to a question that already covers this.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:10:58+00:00Added an answer on May 15, 2026 at 6:10 am

    One thing you can do to make it more readable is:

    ((Time.zone.now - myActiveRecord.visit_date) / 1.day).to_i
    

    Edit:

    Actually you can get rid of one set of the brackets with:

    (Time.zone.now - myActiveRecord.visit_date).to_i / 1.day
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feeling that this is stupid question, but I'll ask anyway... I
I have a feeling that this is a subjective question, but perhaps there's something
I have the feeling the answer to this question is no but I figured
I have a feeling this is a stupid question but I can't find the
I have a feeling that I am going to ask a stupid question, yet
I have a feeling this XML is not valid, can someone please explain why?
I have a feeling that this query is pretty easy to construct, I just
I have a feeling I am completely borking this MySQL query but I'll ask
I somehow have the feeling that modern systems, including runtime libraries, this exception handler
I have a feeling that I'm missing something simple here but can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.