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 ?
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?
Convert as appropriate.