WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   PHP Funktion gesucht (http://www.wcm.at/forum/showthread.php?t=184919)

hewlett 07.02.2006 17:46

PHP Funktion gesucht
 
hi,

ich suche eine php funktion die folgendes kann:

eingabe:
jahr, monat

rückgabe:
alle tage des monats (eben 30 od. 31 oder eben spez. auch für den februar) in einem array

jak 07.02.2006 18:53

Kenne keine solche Funktion, kann man aber leicht selbst schreiben:

Code:

function getDaysPerMonth($year, $month){
  $daysPerMonth = Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  $days = 0;
  $isLeapYear = false;
  if(($month < 1) || ($month > 12)) return false;
  if($month == 2) {
    //every 4th year is a leap year, years like 100, 200, 300, 1900 are not,
    // 400, 800, 2000 are leap years.
    if($year % 100 == 0){
      $isLeapYear = ((($year/ 100) % 4) == 0);
    } else {
      $isLeapYear = (($year % 4) == 0)
    }
  }
  if($month == 2 && $isLeapYear){
    $days = 29;
  } else {
    $days = $daysPerMonth($month);
  }
  $daysInMonth = Array();
  for($i = 0; $i < $days; $i++) $daysInMonth[] = $i
  return $daysInMonth
}

Wenn dich die Wochentage interessieren (Montag, Dienstag etc.) würde ich mir den ersten Wochentag über:
Code:

$startday = date('w',strtotime($year.($month < 10 ? '0' : '').$month.'01'));
holen und den Rest dann mit switch ($i+$startday % 7){case 0: ....} machen.

Siehe http://at.php.net/manual/de/function.strtotime.php und http://at.php.net/manual/de/function.date.php

jak

hewlett 07.02.2006 18:54

thx

T.dot 07.02.2006 19:19

Die Anzahl der Tage kannst du grundsätzlich einfach ermitteln.

laut http://de.php.net/manual/de/function.date.php geht das mit date('t',Datum)

mfg Thomas


Alle Zeitangaben in WEZ +2. Es ist jetzt 17:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag