note 28416 added to function.mktime
| From: | rafaelchacon at terra dot es | Date: | Sun, 12 Jan 2003 18:14:09 +0000 |
| Subject: | note 28416 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42024@lists.php.net to get a copy of this message | ||
To get all dates in an interval of dates (23/09/2002 and 12/01/2003, in example), you can use mktime
combinated with date in that way:
$fechaInicial="23/09/2002";
$fechaFinal="12/01/2003";
//this array must be filled with all months
$mesesEN=array("Jan",...,"Dec");
$d1=intval(substr($fechaInicial,0,2));
$m1=intval(substr($fechaInicial,3,2));
$a1=intval(substr($fechaInicial,6,4));
$d2=intval(substr($fechaFinal,0,2));
$m2=intval(substr($fechaFinal,3,2));
$a2=intval(substr($fechaFinal,6,4));
$mFechaInicial=mktime(0,0,0,$m1,$d1,$a1);
$mFechaFinal=mktime(0,0,0,$m2,$d2,$a2);
for($i=$mFechaInicial;$i<=$mFechaFinal+86400;$i+=86400)
{
//this is an entire line, separated here due to space
echo date("d/m/Y",$i).
" - formated date: ".
substr(date("d/m/Y",$i),0,2)."/".
$mesesEN[intval(substr(date("d/m/Y",$i),3,2))-1].
"/".substr(date("d/m/Y",$i),6,4)."<br>";
}
Note that 86400 is a step used to increment a date in a day. The result of this script is a list of
dates between $fechaInicial y $fechaFinal, and formated using date function.
--
http://www.php.net/manual/en/function.mktime.php
http://master.php.net/manage/user-notes.php?action=edit+28416
http://master.php.net/manage/user-notes.php?action=delete+28416
http://master.php.net/manage/user-notes.php?action=reject+28416