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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:43:30+00:00 2026-06-13T13:43:30+00:00

From a database, I’m trying to find profiles that have been updated in the

  • 0

From a database, I’m trying to find profiles that have been updated in the last X days and group them based on date.

My SQL structure looks like this:
id (int)
date_modified (date)

which produces a result something like this:

+----+---------------+  
| id | date_modified |  
+----+---------------+  
| 86 | 2012-06-22    |  
| 87 | 2012-06-22    |  
| 88 | 2012-06-22    |  
| 89 | 2012-06-22    |  
| 63 | 2011-10-31    |
| 72 | 2012-02-06    |
| 60 | 2011-10-17    |
| 71 | 2012-02-29    |
| 69 | 2011-11-18    |
| 76 | 2012-02-29    |
| 70 | 2011-11-18    |
| 75 | 2012-02-29    |
| 73 | 2012-02-06    |
| 74 | 2012-02-28    |
| 77 | 2012-02-29    |
| 80 | 2012-05-07    |
| 82 | 2012-06-12    |
| 83 | 2012-08-15    |
| 84 | 2012-09-07    |
| 85 | 2012-08-15    |
+----+---------------+

Ideally, I would want to work the query so it produces a result like this:

+-------+----------+  
| total | days_ago |  
+-------+----------+  
| 4     | 1        |
| 6     | 2        |
| 8     | 3        |  
| 12    | 7        |
| 3     | 30       |
| 55    | 90       |  
| 28    | 180      |  
| 37    | 270      |  
| 42    | 360      |  
+----+-------------+

Where it’s converting the date_modified to a number of days ago and grouping it in the increments shown above.

I’m assuming this would be possible using cases in the select query, but I’m a bit at a loss for how to go about doing it.

  • 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-13T13:43:31+00:00Added an answer on June 13, 2026 at 1:43 pm

    You need to use the DATEDIFF MySQL function:

    DATEDIFF() returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

    In your case, it’s simply solved by using

    SELECT COUNT(date_modified) as total, DATEDIFF(date_modified, NOW()) as days_ago FROM mytable GROUP BY date_modified;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am trying to retrieve values from database. I have a row which
I have TreeView Populating from Database And I am Trying to detect the user
i have user data from database that parse inside p element . if user
i have user data from database that parse inside p element . if user
My controller get datas from database model, and sends them to view. In view
i have table from database this table has 400000 row in my asp page
I need to select from database banks which have the minimum <= 50 and
I get a string from database that includes a HTML styling (not sure what
I have some data from database coming out in a loop. Each of these
I am getting query from database. Using that query I need to run that

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.