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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:21:29+00:00 2026-06-03T12:21:29+00:00

I have got two dates in php $date1 = ‘May 3, 2012 10:38:22 GMT’

  • 0

I have got two dates in php

$date1 = 'May 3, 2012 10:38:22 GMT'

$date2 = '06 Apr 2012 07:22:21 GMT'

Then I subtract both of them

$date2 - $date1

, and get

Result:6

Why is the result 6 and not 27? … ? How can I subtract the two dates, and make it return me a result based on month differences while subtracting the years & days & time ?

  • 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-03T12:21:34+00:00Added an answer on June 3, 2026 at 12:21 pm

    Part 1: Why is the result 6?

    The dates are simply strings when you first subtract them. PHP attempts to convert them to integers. It does this by converting until the first non-number. So, date2 become 6 and date1 becomes 0.

    Part 2: How do you get it to work?

    $datetime1 = strtotime('May 3, 2012 10:38:22 GMT');
    $datetime2 = strtotime('06 Apr 2012 07:22:21 GMT');
    
    $secs = $datetime2 - $datetime1;// == <seconds between the two times>
    $days = $secs / 86400;
    

    Convert as appropriate.

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

Sidebar

Related Questions

I have a two dates $date1=03/17/2012 9:00 PM; $date2=03/17/2012 9:40 PM; I have to
I have two dates.Got them from something like...... Calendar c=Calendar.getInstance(); year=c.get(c.YEAR); month=c.get(c.MONTH); month++; date=c.get(c.DATE);
I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
I've got two hard disks in my computer, and have installed Solaris 10u8 on
I've got two Activities. In one I calculate some things and therefore I have
I have got as follows: use constant ABC => ('one', 'two', 'three'); and I
I have the following problem. I got two forms on my web page. On
Possible Duplicate: JavaScript: formatting number with exactly two decimals Now that I have got
I have two websites that post news information. I just got a request to
I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User

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.