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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:49:28+00:00 2026-06-04T01:49:28+00:00

Possible Duplicate: Find Month difference in php? My server hosts multiple websites, and with

  • 0

Possible Duplicate:
Find Month difference in php?

My server hosts multiple websites, and with some of the librarys I am using, it will be very difficult upgrading to php 5.3. I plan to do it in the near future, but not at the moment.

I have two timestamps, and I want to calculate how many months are between them. PHP 5.3 has the datetime.diff function, but since I am on 5.2, I currently can not use this.

What alternatives are there for me? I know I can just grab the seconds by subtracting the timestamps and then get the months by assuming every month has 30 days, but I will be needing an accurate result.

Your help is much appreciated.

  • 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-04T01:49:30+00:00Added an answer on June 4, 2026 at 1:49 am

    Personally I go for this method:

    $from = explode("-",date("Y-m-d",$fromStamp));
    $to = explode("-",date("Y-m-d",$toStamp));
    $months = ($to[0]-$from[0])*12+$to[1]-$from[1];
    if( $to[1] == $from[1] && $to[2] > $from[2]) $months--; // incomplete month
    if( $to[1] == ($from[1]+1)%12 && $to[2] < $from[2]) $months--; // other side
    // result in $months
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to find number of days between two dates using php I'm
Possible Duplicate: How to find number of days between two dates using php If
Possible Duplicate: how to find leap year? What will be the exact definition of
Possible Duplicate: Given a time, how can I find the time one month ago
Possible Duplicate: Find url from string with php I found this code: but 2
Possible Duplicate: How to find all substrings of a string in PHP Find all
Possible Duplicate: How to find out where a function is defined? included php file
Possible Duplicate: Get first day of week in PHP? Hi, I want to find
Possible Duplicate: Find last character in a string in PHP How can I know
Possible Duplicate: How to find foreign key dependencies in SQL Server? i am trying

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.