Monday, November 16, 2009

PHP date calculation problem?

When I run this programe, the list will show only the date (15,16,17 …) but I want it to display like 15.02.2008 and so on, how can I do it ?











%26lt;select name="From" size="1" type="text" %26gt;





%26lt;option select="selected"%26gt;%26lt;?php echo $_SESSION['from']; ?%26gt;%26lt;/option%26gt;











%26lt;?php

















$d1= trim($_POST['Departuredate']);





$d2= trim($_POST['Arrivaldate']);























while (date($d2) %26lt;= date($d1)){











print "%26lt;option%26gt;" . date('d.m.Y', $d2) . "%26lt;/option%26gt;" ;











$d3= date($d2) + 1;











}





?%26gt;











%26lt;/select%26gt;























Thanks,

PHP date calculation problem?
The problem is that you need to use strtotime to convert to a timestamp first. Make sure that $d1 and $d2 are full dates - "02/18/2008" for instance.





%26lt;?php





$d1= trim($_POST['Departuredate']);


$d2= trim($_POST['Arrivaldate']);





$i = strtotime($d2);


$end = strtotime($d1);


$j = 0;


while ($i %26lt;= $end){


print "%26lt;option%26gt;" . date('d.m.Y', $i) . "%26lt;/option%26gt;" ;


$i = strtotime($d2 +$j days);


$j++;


}





?%26gt;


No comments:

Post a Comment