Question

I have this piece of code:

<?php

    setlocale(LC_ALL,"es_ES");
    $contador = 1;
    $diaActual = time();

    while ($contador <= 7) {

        echo date("D j-n-Y", $diaActual)."<br><br>";
        $contador++;
        $diaActual = strtotime("+1 day", $diaActual);

    }


?>

Result:

Tue 13-5-2014

Wed 14-5-2014

Thu 15-5-2014

Fri 16-5-2014

Sat 17-5-2014

Sun 18-5-2014

Mon 19-5-2014

Why isn't working?

Was it helpful?

Solution

From the manual about date()

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().

So use strftime():

print strftime("%a %d-%m-%Y");

To sum up always one day, just use a timestamp like:

for ($time = time(), $contador = 1;
     $contador <= 7;
     $contador++, $time = strtotime('+1 day', $time)) {
    print strftime("%a %d-%m-%Y", $time)."<br />\n";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top