Search code examples
phpvariablesstrftime

How to get the next Monday using PHP strtotime?


I am using this to variable to get the current month:

setlocale(LC_TIME, array('ro.utf-8', 'ro_RO.UTF-8', 'ro_RO.utf-8', 'ro', 'ro_RO', 'ro_RO.ISO8859-2')); 

$month = " " . strftime('%B',time()) . " ";

echo date("d", strtotime("next monday")); echo $luna;  echo date("Y", strtotime("next monday"));

Currently it's working good, but when the month it's almost end and the next Monday it's next month, it will show the wrong month because my variable is getting the current month.

I do not know how to fix this.


Solution

  • You have an error here strftime('%B',time()), actualy it should be strftime('%B',strtotime("next monday")).

    <?php
    
    $next_monday_timestamp = strtotime("next monday");
    echo "Next monday will be on " . strftime("%B", $next_monday_timestamp);