tags:

views:

54

answers:

1

hi to all

Provided the code stated below, the output are (see below). My question is why after 2009/11/01 it follow's by 2009/11/30 and 2009/12/30 instead of 2009/12/01. From 2009/06/01 ~ 2009/11/01 there is no problem.

Any suggestion would greatly appreciated

Thanks in advance

Tirso

output
2009/06/01
2009/07/01
2009/08/01
2009/09/01
2009/10/01
2009/11/01
2009/11/30
2009/12/30

my code

<?php

$startdate = "2009/06/01";
$enddate = "2009/12/31";

$start = strtotime($startdate); 
$end = strtotime($enddate); 

$currentdate = $start; 
while($currentdate < $end)
{
 $cur_date = date('Y/m/d',$currentdate);
 $month = date('m', $currentdate); 
 $year = date('Y', $currentdate); 
 $monthLength = daysOfMonth($month, $year); 
 $currentdate += $monthLength; 

 echo $cur_date . "<br />"; 
}


function daysOfMonth($month, $year)
{
 return (86400 * date("t", strtotime($year."-".$month."-01")));
} 

?>
+1  A: 
<?php

$startdate = "2009/06/01";
$enddate = "2009/12/31";

$start = strtotime($startdate);
$end = strtotime($enddate);

$currentdate = $start;
while($currentdate < $end)
{
        $cur_date = date('Y/m/d', $currentdate);

        $currentdate = strtotime('+1 month', $currentdate);

        echo $cur_date . "<br />";
}

?>
Álvaro G. Vicario
hi alvaro, sorry for my late replied, due to Christmas holiday I wasn't able to work and read your answer. BTW, your code works perfectly, how about if the start date not started with day 01, let say $startdate = "2009/06/06" ?Thank you very much
tirso
Is it a new question? Once you have a Unix timestamp, you have a great choice of functions to manipulate it. You can extract fragments with date() and generate new timestamps with mktime().
Álvaro G. Vicario
hi alvaro thanks.Tirso
tirso