Hello. I want to show all the saturdays of this month, I tried the following code but its not working, can somebody help me? $dtFirstDay = date("j/n/Y", mktime(0, 0, 0, date("m") , date("d")-date("d")+1, date("Y"))); $dtLastDay = date("j/n/Y", mktime(0, 0, 0, date("m")+1 , date("d")-date("d"), date("Y"))); for($date = $dbFirstDay ; $date < $dtLastDay; $date = mktime(0,0,0,date("m", $date),date("d", $date)+1,date("Y", $date))){ if(date('w' ,$date) == 0){ echo $date; } } PHP:
<?php $total_days = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')); echo "Their are ".round($total_days / 7)." Saturdays within ".date('M, Y'); ?> PHP:
<?php //$total_days = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y')); $total_days = date('t',strtotime('today')); $day_nums = range(1, $total_days); $dates = array(); $i = 0; foreach($day_nums as $num){ $i++; $dates[$i] = $num.' '.date('M').' '.date('Y'); } $strdates = array(); $i = 0; foreach($dates as $date){ $i++; $strdates[$i] = strtotime($date); } $saturdays = array(); $i = 0; foreach($strdates as $strdate){ $strdate_info = getdate($strdate); if ($strdate_info['weekday'] == "Saturday"){ $i++; $saturdays[$i] = $strdate_info['mday'].' '.date('M').' '.date('Y'); } } //returns an array of saturdays with their date numbers... print_r($saturdays); ?> PHP: Could have been done another way, but this is what I could think of.
I had a little look around too... very basic but you might find it useful, it will echo out the next 4 Saturdays <?php echo date('l jS F (Y-m-d)', strtotime('this Saturday')); echo '<br />'; echo date('l jS F (Y-m-d)', strtotime('next Saturday')); echo '<br />'; echo date('l jS F (Y-m-d)', strtotime('third Saturday')); echo '<br />'; echo date('l jS F (Y-m-d)', strtotime('fourth Saturday')); ?> PHP: Equals: Saturday 15th May (2010-05-15) Saturday 22nd May (2010-05-22) Saturday 5th June (2010-06-05) Saturday 12th June (2010-06-12) or this <?php echo date('l jS F', strtotime('this Saturday')); echo '<br />'; echo date('l jS F', strtotime('next Saturday')); echo '<br />'; echo date('l jS F', strtotime('third Saturday')); echo '<br />'; echo date('l jS F', strtotime('fourth Saturday')); ?> PHP: Equals: Saturday 15th May Saturday 22nd May Saturday 5th June Saturday 12th June