Search code examples
phptimestrftime

PHP get next month issue


I'm trying to get the current, the next and the after next month by php.

This is my current php:

setlocale(LC_TIME, "de_DE.utf8");
$thismonth = strftime("%B");
$nextmonth = strftime( '%B', strtotime( '+1 month', mktime( 0, 0, 0, $month, 1, $year ) ) );
$overnextmonth = strftime( '%B', strtotime( '+2 month', mktime( 0, 0, 0, $month, 1, $year ) ) );

The month name should be in german so I'm using setlocale(LC_TIME, "de_DE.utf8");.

The ouput is: Januar (january), Januar (january), Februar (february). I can't figure the issue out.


Solution

  • use this setlocale (LC_TIME,"de_DE"); it will work

    <?php
    setlocale (LC_TIME,"de_DE"); 
    echo $thismonth = strftime("%B");
    echo $nextmonth = strftime( '%B', strtotime( '+1 month', mktime( 0, 0, 0, 1, 1, 2017 ) ) );
    echo $overnextmonth = strftime( '%B', strtotime( '+2 month', mktime( 0, 0, 0, 2, 1, 2017 ) ) );
    
    ?>
    

    output

    output picture