PHP: tage zwischen 2 daten?
Umlüx 19.09.2005 - 14:59 910 3
Umlüx
Huge Metal Fan
|
ich hab ein start und ein enddatum und möchte ausrechnen wieviele tage dazwischenliegen, exkl. wochenende (sa, so)). vielleicht hat sowas wer bei der hand oder mal selbst geschrieben und wäre freundlicherweise bereit es mit mir zu teilen?  danke!
Bearbeitet von Umlüx am 20.09.2005, 08:18
|
rettich
Legendwaffle, waffle!
|
|
semteX
hasst die KI
|
ich würd die funktion ausm pear package nehmen... die funkion die rettich gepostet hat ist angeblich buggy (laut comments..)
|
Umlüx
Huge Metal Fan
|
< 1 minute google mit "dateadd php" und dann korrigiert auf "datediff php"
naja erst mal wissen dass man nach diesen stichwörtern suchen muss. ich hab lange nach tage berechnen, arbeitstage berechnen usw.. gegoogelt. also nur falls du mir jetzt faulheit vorwerfen willst  Ich hab das ganze jetzt übrigens so gelöst function count_workdays($date1,$date2){
$firstdate = strtotime($date1);
$lastdate = strtotime($date2);
$firstday = date(w,$firstdate);
$lastday = date(w,$lastdate);
$totaldays = intval(($lastdate-$firstdate)/86400)+1;
if ($totaldays<=7 && $firstday<=$lastday){
$workdays = $lastday-$firstday+1;
if ($firstday==0)
$workdays = $workdays-1;
if ($lastday==6)
$workdays = $workdays-1;
}
else {
if ($firstday==0)
$firstweek = 5;
else
$firstweek = 6-$firstday;
$totalfw = 7-$firstday;
if ($lastday==6)
$lastweek = 5;
else
$lastweek = $lastday;
$totallw = $lastday+1;
if (($totalfw+$totallw)>=$totaldays)
$midweeks = 0;
else
$midweeks = (($totaldays-$totalfw-$totallw)/7)*5;
$workdays = $firstweek+$midweeks+$lastweek;
}
return ($workdays);
}
(nicht ganz auf meinem mist gewachsen, aber funzt)
|