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

  • SEARCH
  • Home
  • 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 7851563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:12:50+00:00 2026-06-02T19:12:50+00:00

I have two datetime columns in a User / users table: created_at and birthdate

  • 0

I have two datetime columns in a User/users table: created_at and birthdate. I’d like to find users whose birthdate is less than 13 years before their creation date.

The equivalent Rails if statement would be ((created_at - birthdate) < 13.years)

How do I translate this to an ActiveRecord query (one that’ll work on PostgreSQL)? Is this even possible, or will I have to iterate over all records manually?

  • 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-06-02T19:12:51+00:00Added an answer on June 2, 2026 at 7:12 pm

    The easiest way to do this is to use an interval, then it is pretty much a straight transliteration of the Rails version:

    User.where(%q{created_at - birthdate < interval '13 years'})
    

    The difference between two timestamps (or a timestamp and a date) is an interval so you just need the appropriate value on the right side of your comparison.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two datetime columns in a table, and I would like to select
I have a table called Sessions with two datetime columns: start and end. For
I have a table contains various columns including two DateTime column, Start and End
Please help me: I have two columns in mysql table - date1 (datetime) and
I have two columns in table users namely registerDate and lastVisitDate which consist of
I have a table with two DATETIME columns: Column1 Column2 1/1/1900 12:20:45 1/1/1900 23:22:25
If I have a table that (among other columns) has two DATETIME columns, how
I have a table with two DATETIME columns. One of them is never NULL,
I'd like to have two columns in a database, one for tracking whether or
I have two tables, both with the same columns. The first table contains original

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.