Days of the week dynamically

-1

I want to show the days of the week (Tuesday 2 December) in one table per week from the date function. In other words, the table has 7 columns and starts on Sunday until Saturday. For example:

<td>Dia da semana</td>
    
asked by anonymous 02.12.2014 / 13:48

1 answer

1

You can use PHP's date() function to get the day of the week

echo date("l"); //exibe o nome do dia da semana, em inglês
echo date("N"); //exibe a representação numérica do dia da semana

echo date("d")." "; //exibe o dia
echo date("m")." "; //exibe o mês
echo date("Y")." "; //exibe o ano

As a parameter you pass the desired output format ("N" returns the ISO-8601 numeric representation of the day of the week)

Using date("N") you can build a simple function that returns the day of the week in Portuguese.

echo dayOfWeek(date("N")); //exibe o dia da semana em portugues

function dayOfWeek($day){
    switch ($day) {
        case 1:
            return "Segunda";
        case 2:
            return "Terça";
        case 3:
            return "Quarta";
        case 4:
            return "Quinta";
        case 5:
            return "Sexta";
        case 6:
            return "Sábado";
        case 7:
            return "Domingo";
    }
}

On the issue of generating a table with the days of the week ...

echo "<table>";
echo "<tr>";
for ($i=1; $i <= 7 ; $i++) { 
    echo "<td>";
    echo dayOfWeek($i);
    echo "</td>";
}
echo "</tr>";
echo "</table>";
    
02.12.2014 / 14:10