Page 1 of 1

date calculations giving wrong results

Posted: Wed Apr 02, 2008 9:57 am
by mcog_esteban
Hello.
Using this code, why i'm having diferent results with this code ?

Code: Select all

 
$day = 60*60*24;
$status = 'Wed Aug 11 13:03:20 WEST 2010';
$expire_date = date("d/m/Y", strtotime($status));
 
var_dump($expire_date);
$expiration_date = strtotime($expire_date);
 
$today = date("d/m/Y");
var_dump($today);
 
var_dump( ($expiration_date-strtotime($today))/$day );
 
$today = date("d/m/Y", strtotime('now'));
 
var_dump( ($expiration_date-strtotime($today))/$day );
 
$today = strtotime('2 April 2008');
$august_11_2010 = strtotime('11 August 2010');
 
var_dump( ($august_11_2010-$today)/$day);
 

Results:

Code: Select all

 
string(10) "11/08/2010"
string(10) "02/04/2008"
int(1008)
int(1008)
int(861)
 

:banghead: what i'm missing here ?

Re: date calculations giving wrong results

Posted: Wed Apr 02, 2008 10:09 am
by John Cartwright
Would you care to explain what the problem is? I don't like puzzles :)

Re: date calculations giving wrong results

Posted: Wed Apr 02, 2008 10:23 am
by mcog_esteban
Jcart wrote:Would you care to explain what the problem is? I don't like puzzles :)
Sorry, i've figured it out how to correct the calculs.

Re: date calculations giving wrong results

Posted: Wed Apr 02, 2008 10:25 am
by onion2k
PHP uses US time formatting ... if you put "2/4/2010" into strtotime() it assumes you mean Feb 4th rather than 2nd April.

Re: date calculations giving wrong results

Posted: Wed Apr 02, 2008 10:30 am
by mcog_esteban
onion2k wrote:PHP uses US time formatting ... if you put "2/4/2010" into strtotime() it assumes you mean Feb 4th rather than 2nd April.
that must have been my error.