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 6872067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:52:53+00:00 2026-05-27T03:52:53+00:00

I have a table of users which has a date field for their birthday:

  • 0

I have a table of users which has a date field for their birthday:

buddy_auto_id    int(11) PK

user_id          varchar(128)

buddy_user_id    varchar(128)

buddy_name       varchar(128)

buddy_bday       date

buddyuser_id     varchar(20)

active           enum('Yes','No')

requestsentby    int(11)

whenrequested    timestamp

I’m trying to find the 3 users whose birthdays fall soonest compared to todays date and then display the number of days until their birthday ordered by soonest first.

Is this possible within a SQL query or do I have to pull it out and let PHP do the equation?

Many thanks

  • 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-27T03:52:54+00:00Added an answer on May 27, 2026 at 3:52 am

    This should be possible with SQL. You need to compare the current date with a birthday expressed as from this year or next year, depending on whether we’ve past it in the current year. Once you have this “next birthday” date, use DATEDIFF function to determine number of days distant from current date.

    SELECT *,
        DATEDIFF(
            # determine date of next birthday by adding age in years to birthday year
            DATE_ADD(buddy_bday, INTERVAL
                YEAR(CURDATE())-YEAR(buddy_bday)
                # add a year if we celebrated birthday already this year
                +(MONTH(buddy_bday)<MONTH(CURDATE()) OR (MONTH(buddy_bday)=MONTH(CURDATE()) AND DAY(buddy_bday) < DAY(CURDATE())))
            YEAR),
            CURDATE())
        AS days_to_next_bday
    FROM user_table
    ORDER BY days_to_next_bday
    LIMIT 3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table users which has a primary key userid and a datetime
I have an application which has a Projects table and a Users table. In
I have DLawUserMaster table which has UserID, LoginId and password field. Among them UserId
I have a table User which has the fields (id, first_name, middle_name, last_name). I
I have a User table which has a PrivilegeId foreign key points to a
I have a table in HTML which has three columns i.e Error - User
Let's say I have a table called Users which represents registered users of a
I have a table in which users store scores and other information about said
Say I have a table called Users, which contains your typical information: Id, Name,
So I have a mySQL database with a 'users' table which includes a username,

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.