note 28416 deleted from function.mktime by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 13:11:07 +0000 |
| Subject: | note 28416 deleted from function.mktime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59876@lists.php.net to get a copy of this message | ||
Note Submitter: rafaelchacon@terra.es
----
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.