25 september 2007

PHP: strtotime('today') != strtotime('now')

This can be usefull for people that are switching from PHP4 to PHP5, be carefull when you use the strtotime-function

In PHP 4.4.6 following code return equal timestamps, as in PHP 5.1.4 they return other timestamps

PHP 4.4.6

<?php
// returns the current timestamp (25/09/2007 20:21:52)
echo date('d/m/Y H:i:s'strtotime('today'));
// returns the current timestamp (25/09/2007 20:21:52)
echo date('d/m/Y H:i:s'strtotime('now'));
?>

PHP 5

<?php
// returns the current date at midnight (25/09/2007 00:00:00)
echo date('d/m/Y H:i:s'strtotime('today'));
// returns the current timestamp (25/09/2007 20:21:52)
echo date('d/m/Y H:i:s'strtotime('now'));
?>

Same results, but don't using the strtotime-method

<?php
// returns the current date at midnight (25/09/2007 00:00:00)
echo date('d/m/Y H:i:s'mktime(0,0,0)); 
// returns the current timestamp (25/09/2007 20:21:52)
echo date('d/m/Y H:i:s') ;
?>

Dit artikel gaat over: , , , , , , , . PHP: strtotime('today') != strtotime('now') werd geschreven door Tijs.
Er zijn al 2 reacties.

Reacties

Frank

Frank schreef:
26/09/07

T is typisch php om dat zo "laat" in de taal (4 -&gt; 5) te gaan veranderen, maar eigenlijk is het logischer zo.

arun

arun schreef:
27/05/10

its very helpful for begginers

Reageer velden gemarkeerd met een sterretje zijn verplicht

*