php function returns false -
php function returns false -
the next php function returns n-th weekday of month, e.g. 3rd quarta-feira in jan 2012 in form 18-1-2012:
<?php function giventhday($month, $year, $no, $day) { $counter = 0; for($i=1;$i<=31;$i++) { //schleife für 31 tage if(!checkdate($month, $i, $year)) { //wenn datum nicht existiert (bspw. 30. februar) zu nächstem schleifendurchlauf springen continue; } else { if(date('l', strtotime($i.'-'.$month.'-'.$year))==$day) { //wenn generiertes datum gleicher wochentag wie gesuchter tag $day $counter++; //dann $counter um eins erhöhen if($counter==$no) { //falls $counter==$no, falls bspw. dritter ($no==$counter==3) mittwoch gefunden, datum zurückgeben homecoming $i.'-'.$month.'-'.$year; } } } } homecoming false; //existiert nicht, bspw. fünfter sonntag gibt es nicht in jedem monat } ?> if date doesn't exist (e.g. 5th fri in jan 2012), returns false.
this works fine examples like:
giventhday(1, 2012, 3, "wednesday"); giventhday(1, 2020, 3, "wednesday"); giventhday(1, 2031, 3, "wednesday"); but
giventhday(1, 2038, 3, "wednesday"); on, returns false though every jan has more 3 wednesdays!
i tried hard find out reason unusual behaviour can't figure out. can help me?
2038 out of scope, max date beingness 2037 (on 32 bits architecture). time() unix timestamp (starting 1970-1-1 00:00:00).
php
Comments
Post a Comment