1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <?php
function GetDays($dDate, $fDate, $aPeriode)
{
list($aaaa, $mm, $jj) = explode('-', $dDate);
if ($aaaa == $aPeriode) $dUnix = mktime(0, 0, 0, $mm, $jj, $aaaa);
else $dUnix = mktime(0, 0, 0, 1, 1, $aPeriode);
list($aaaa, $mm, $jj) = explode('-', $fDate);
if ($aaaa == $aPeriode) $fUnix = mktime(23, 59, 59, $mm, $jj, $aaaa);
else $fUnix = mktime(23, 59, 59, 12, 31, $aPeriode);
return ceil(($fUnix-$dUnix)/86400);
}
$id_horaire = 5;
$id_salaire = 10;
$annee = 2008;
$req = 'SELECT `date_debut`, `date_fin` '
.'FROM `travailler` '
.'WHERE `id_horaire` = '.$id_horaire.' '
.' AND `id_salarie` = '.$id_salaire.' '
.' AND (YEAR(`date_debut`) = '.$annee.' OR YEAR(`date_fin`) = '.$annee.')';
if (!mysql_connect('localhost', 'root', 'xxf8zmi8')
|| !mysql_select_db('test')
|| !$res = mysql_query($req))
die(mysql_error());
mysql_close();
$jours = 0;
while (list($debut, $fin) = mysql_fetch_row($res))
$jours += GetDays($debut, $fin, $annee);
echo $jours;
?> |
Partager