note 85351 added to function.date

From: Date: Wed, 27 Aug 2008 04:02:42 +0000
Subject: note 85351 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-143855@lists.php.net to get a copy of this message
/* * Retorna todos as segundas e/ou terças... em um array * 0 - domingo, 1-Segunda,... * * @param $data_i - Data Inicial (yyyy-mm-dd) * @param $data_f - Data Final (yyyy-mm-dd); * @param $_filter = Array() - Ex.: $_filter = array(0,2,4); 0-Domingo, 2-Terca 4-Quinta * @param $week_start - For return index, week start in 0|1 * * * http://www.qprocura.com.br */ function ArrayDiasDaSemana($data_i, $data_f, $_filter = array(), $week_start=0) { list($y1, $m1, $d1) = split('-', $data_i); list($y2, $m2, $d2) = split('-', $data_f); $end = 0; $_week = array(); $has_filter = count($_filter); for($year=intval($y1); $year <= $y2; $year++) { for($month=intval($m1); $month <= 12; $month++) { for($day=intval($d1); $day <= 31; $day++) { if($month < 10) $m = '0'.$month; else $m = $month; if($day < 10) $d = '0'.$day; else $d = $day; if(!checkdate($m,$d,$year)) continue; $week = date('w', mktime(0,0,0,$m,$d,$year)); if($week_start) $week += $week_start; if($has_filter) { if(in_array($week, $_filter)) { $_week[$week][] = $year.'-'.$m.'-'.$d; } } else { $_week[$week][] = $year.'-'.$m.'-'.$d; } if("$year-$m-$d" == "$y2-$m2-$d2") { $end=1; break; } } if($end) break; } if($end) break; } return $_week; } Exemplo: Retornar Segundas e Sextas print_r(ArrayDiasDaSemana('2008-08-01','2008-08-31',array(2,6),1)); Array ( [6] => Array ( [0] => 2008-08-01 [1] => 2008-08-08 [2] => 2008-08-15 [3] => 2008-08-22 [4] => 2008-08-29 ) [2] => Array ( [0] => 2008-08-04 [1] => 2008-08-11 [2] => 2008-08-18 [3] => 2008-08-25 ) ) ---- Server IP: 200.185.126.110 Probable Submitter: 189.26.44.200 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/85351 Del: integrated -- https://master.php.net/note/delete/85351/integrated Del: useless -- https://master.php.net/note/delete/85351/useless Del: bad code -- https://master.php.net/note/delete/85351/bad+code Del: spam -- https://master.php.net/note/delete/85351/spam Del: non-english -- https://master.php.net/note/delete/85351/non-english Del: in docs -- https://master.php.net/note/delete/85351/in+docs Del: other reasons-- https://master.php.net/note/delete/85351 Reject -- https://master.php.net/note/reject/85351 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143855) next »