WCM - Das österreichische Computer Magazin Forenübersicht
 

Zurück   WCM Forum > Rat & Tat > Programmierung

Programmierung Rat & Tat für Programmierer

Microsoft KARRIERECAMPUS

Antwort
 
Themen-Optionen Ansicht
Alt 07.02.2006, 17:46   #1
hewlett
Inventar
 
Registriert seit: 08.11.2000
Alter: 42
Beiträge: 1.524


Standard 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
____________________________________
H.E.W.L.E.T.T.: Hydraulic Electronic Worker Limited to Exploration and Terran Troubleshooting
hewlett ist offline   Mit Zitat antworten
Alt 07.02.2006, 18:53   #2
jak
Inventar
 
Registriert seit: 13.06.2001
Beiträge: 1.830


Standard

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
____________________________________
Join the DNRC | Godwin\'s Law (thx@stona)
Documentation is like sex: If it\'s good, it\'s very, very good. If it\'s bad, it\'s better than nothing.
\"In theory, theory and practice are the same. In practice, they are not\" (Lawrence Berra)
jak ist offline   Mit Zitat antworten
Alt 07.02.2006, 18:54   #3
hewlett
Inventar
 
Registriert seit: 08.11.2000
Alter: 42
Beiträge: 1.524


Standard

thx
____________________________________
H.E.W.L.E.T.T.: Hydraulic Electronic Worker Limited to Exploration and Terran Troubleshooting
hewlett ist offline   Mit Zitat antworten
Alt 07.02.2006, 19:19   #4
T.dot
Master
 
Registriert seit: 13.08.2003
Beiträge: 624


Standard

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
T.dot ist offline   Mit Zitat antworten
Antwort


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu


Alle Zeitangaben in WEZ +2. Es ist jetzt 11:16 Uhr.


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