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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:48:24+00:00 2026-06-16T11:48:24+00:00

In mySql how can I calculate the months and years from a ‘given date’

  • 0

In mySql how can I calculate the months and years from a ‘given date’ till now. That ‘given date’ will be selected from a table. Or is this something I’ll have to use php to do?

So the sql will be select min(datecol) from table where userid = 12;

I came across this here select DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), '2009-12-26')), '%c months and %Y years'); but this gives 1 months and 0003 years

Three years is ok, but 1 month is wrong. It should be 36+ months in this case.

  • 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-16T11:48:25+00:00Added an answer on June 16, 2026 at 11:48 am

    To find month

    select 
      period_diff(date_format(now(), '%Y%m'), date_format(`date_field`, '%Y%m')) 
      as months from `your_table`
    

    or this

     SELECT
            12 * (YEAR(now()) - YEAR('2012-02-26')) + 
            (MONTH(now()) - MONTH('2012-02-26')) AS months
    

    refer the Mevin Babu link to find year

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

Sidebar

Related Questions

Is there a mysql syntax that can preform a select values from a table,
I've learned that MySQL can compress communication between servers and clients. Compression is used
In MySQL you can use the syntax DELETE t1,t2 FROM table1 AS t1 INNER
I read that MySQL fulltext search can cause table locking . It means people
I have to look into solutions for providing a MySQL database that can handle
I read a mysql timestamp can only hold a value from 19700101000000 to sometime
I want to calculate a 12 month moving average from a MySQL column. The
Good evening. How can I calculate periods of 6 months (semesters or a two
Good morning, mysql query which displays cases that have a date field completed &
I have a MySQL query that uses two different timestamps that can be perceived

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.