星期三的日历,但1月失踪

I tried to write a Wednesday calendar, the calendar should only show the Wednesday in a table, and it should be able to write a meeting in the calendar

I tried to change:

strotime('-1 month')

But then it shows no calendar.

function getMittwoch($y, $m)
{
    return new DatePeriod(
        new DateTime("first wednesday of $y-$m"),
        DateInterval::createFromDateString('next wednesday'),
        new DateTime("last day of $y-$m")
    );
}

So last year, it functioned, but now not. The calendar shows only February till December, but the January is missing.

for( $monat=date('m', strtotime('0 month'))+1; $monat<13; $monat++ ){
        foreach (getMittwoch(date('Y'), $monat) as $mittwoch) {
            $tagWert = $mittwoch->format("dmY");

What should I change for 2017?

my script will find all wednesdays in given date:

function getWednesday($y,$m){
    $inmonth=date('t', mktime(0, 0, 0, $m, 1, $y)); ;

    for($i=0;$i<$inmonth;$i++){
        $d=$i+1;
        $timestamp = strtotime("$y-$m-$d");
        $day = date('w', $timestamp);
        if($day==3){
            echo "Wednesday found - $y-$m-$d<br>";
        }
    }
}

getWednesday(2017,1);

Output is:

Wednesday found - 2017-1-4
Wednesday found - 2017-1-11
Wednesday found - 2017-1-18
Wednesday found - 2017-1-25

You can replace the echo with something else of course. I hope it will help you.

Ondrej

The next variation which shows Wednesdays in next months:

function getWednesday($y,$m,$next=1){
    for ($x=0; $x < $next; $x++) {
            $inmonth=date('t', mktime(0, 0, 0, $m, 1, $y)); ;

            for($i=0;$i<$inmonth;$i++){
                $d=$i+1;
                $timestamp = strtotime("$y-$m-$d");
                $day = date('w', $timestamp);

                if($day==3){
                    echo "Wednesday found - $y-$m-$d<br>";
                }
            }

            if($m==12){
                $y++;
                $m=0;
            } 
    $m++;
    }
}

getWednesday($y,$m,$next)

  • $y - year to start counting from
  • $m - month to start
  • $next - next $next months to show (if not used, shows one month)

Sorry , but i did not get on. i want to implement it to my script. So my calender should always show the next Wednesdays of the next six month include 2018. And should start from current day.

    for( $monat=date('m', strtotime('month')); $monat<7; $monat++ ){
        foreach (getMittwoch(date('Y'), $monat) as $mittwoch) {
            
            $tagWert = $mittwoch->format("dmY");
            echo "<tr>";
            echo "<td>";
            echo "<input type=\"radio\" name=\"tag\" value=\"$tagWert\" />". $mittwoch->format("l, d.m.Y");
            echo "</td>";
            echo "<td>";
            echo getVeranstaltung($tagWert)['veranstaltung'];
            echo "</td>";
            echo "</tr>";
        }
    }

</div>