Here is my PHP Code that generate a selectbox with month names + Year. I have 2 Time Stamps that I am using in the loop that start timestamp and end timestamp.
now the problem is for example if my start-timestamp represent 01.07.2011 and as in the loop I am adding only 30 Days to time stamp then i selectbox July will be displayed twice. and if I add 31 Day then may be a month will be skiped.
Is there any function available that can add exact one month for each iteration?
<select name="checkinMonth" class="selectform" id="checkinMonth" >
<?php
for($month = $checkin_timestamp; $month <= $checkout_timestamp; $month += 30*60*60*24) {
$checkin_month = getdate($month);
$option_text = strftime("%B %Y",$month);
$option_value = strftime("%Y%m", $month);
$selected = ($checkin_selected == $option_value ? "selected='selected'" : "");
echo "<option value='{$option_value}' {$selected}>{$option_text}</option>";
}
?>
</select>
Are you looking for something like:
strtotime("+1 month", $myTimestamp);
http://us2.php.net/strtotime
And if you fancy something more verbose, try this:
$tmp_year = date("Y", $month);
$tmp_month = date("m", $month);
$tmp_day = date("d", $month);
$tmp_hour = date("H", $month);
$tmp_min = date("m", $month);
$tmp_sec = date("s", $month);
$month = mktime($tmp_hour, $tmp_minute, $tmp_second, $tmp_month + 1, $tmp_day, $tmp_year);
I guess you'll have to put it in its own function to make it fit in that for-clause :P
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With