844-NOGALIS (844-664-2547)
Nogalis, Inc.
  • Link to Facebook
  • Link to X
  • Link to LinkedIn
  • Link to Mail
  • Company
    • News, Events and Articles
    • About Us
  • Products
    • Infor Lawson Data Archive
    • PeopleSoft Data Archive
    • Oracle Data Archive
  • Services
    • Infor Lawson Support
    • Infor Lawson / CloudSuite Consulting
  • Education & Training
  • Support
  • Contact Us
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

MySQL Formula to Convert Days to Years & Months

Articles, Frontpage Article, News

When working with date and time values in MySQL, it’s common to store durations in days. However, sometimes you need to present those days as a more human-readable format—like years and months. For example, showing “2 years, 3 months” instead of “825 days.”

Here’s a simple way to achieve this using a MySQL formula.


Converting Days to Years and Months

Since MySQL doesn’t have a built-in function to directly convert days into years and months, we can use arithmetic with division (/) and modulo (%) operators.

SELECT

FLOOR(days / 365) AS years,

FLOOR((days % 365) / 30) AS months

FROM

your_table;


How It Works

  • FLOOR(days / 365)
    Divides the total days by 365 to get whole years.
  • (days % 365)
    Gets the leftover days after subtracting the full years.
  • FLOOR((days % 365) / 30)
    Divides the leftover days by 30 to approximate months.

Example

Suppose your table looks like this:

CREATE TABLE durations (days INT);

INSERT INTO durations (days) VALUES (400), (825), (1200);

Running the query:

SELECT

days,

FLOOR(days / 365) AS years,

FLOOR((days % 365) / 30) AS months

FROM durations;

Would produce:

days years months
400 1 1
825 2 3
1200 3 3

Notes and Limitations

  • This method assumes 365 days per year and 30 days per month. It’s an approximation, not a precise calendar conversion.
  • If you need exact calendar-aware calculations (e.g., accounting for leap years or exact month lengths), you’ll need to work with MySQL date functions and actual date values instead of raw day counts.

Final Thoughts

Converting days to years and months in MySQL can be done easily with simple math functions. While the above approach works well for approximations, consider whether you need exact date-based calculations before choosing the method.

If you often store durations in days, this formula provides a quick way to present data in a more user-friendly format.

Retiring Lawson, PeopleSoft, or Oracle? APIX archives the entire application — every table, every year, attachments and security included — into your own AWS account in about 30 days, so you can decommission the legacy system and keep full access to the history.

See how the APIX ERP archive works →

04/14/2026
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on LinkedIn
  • Share on Reddit
  • Share by Mail
https://www.nogalis.com/wp-content/uploads/2026/04/MySQL-Formula-to-Convert-Days-to-Years-Months.jpg 470 470 Angeli Menta https://www.nogalis.com/wp-content/uploads/2013/04/logo-with-slogan-good.png Angeli Menta2026-04-14 08:41:432026-04-09 11:54:26MySQL Formula to Convert Days to Years & Months

LEGACY ERP DATA ARCHIVE SOLUTION



Discover how our clients are leveraging AWS services to archive their Legacy ERP data and provide ubiquitous access to users via a light-weight, secure, and read-only web interface. Secure, Fast, Reliable, and Cost Effective. That is the promise of APIX. Follow the link below to find out more and book a discovery call with our data archive specialist.

BOOK DEMO

© Copyright - Nogalis, Inc. 2026
  • Legal
  • Privacy
  • Contact Us
Link to: Inside the Global Data Center Investment Surge and Why It Matters for ERP Leaders Link to: Inside the Global Data Center Investment Surge and Why It Matters for ERP Leaders Inside the Global Data Center Investment Surge and Why It Matters for ERP L... Link to: Hybrid ERP Deployments Becoming Standard as Industry Grows Link to: Hybrid ERP Deployments Becoming Standard as Industry Grows Hybrid ERP Deployments Becoming Standard as Industry Grows
Scroll to top Scroll to top Scroll to top