Print day of the week in full adding one day

2

I'm trying to print the day of the week in full (Monday, Tuesday ...) of a date returned from the database. However, it is always printing with one day less, for example, instead of Monday printing, it is printing Sunday, I wanted to know what I can put in the line below so that it disappears one day and, instead of displaying 'Sunday', display 'Second' and so on.

The date is coming from the bank in the format YYYY-DD-MM. Ex: 2017-03-07, in this case 07/03 is a Tuesday, but for some reason, Second is being displayed at the time of printing the date.

echo JText::sprintf(JHTML::_('date',  $item->data_inicio, JText::_("l, ")));
    
asked by anonymous 20.02.2017 / 12:56

2 answers

3

The date function receives a Unix Timestamp, not a formatted date.

// Tranformar YYYY-DD-MM em YYYY-MM-DD
$data_formatada = explode('-', $item->data_inicio);
$data_formatada = join( '-', $data_formatada[0], $data_formatada[2], $data_formatada[1] );

echo JText::sprintf(JHTML::_('date',  strtotime( $data_formatada ), JText::_("l, ")));
    
20.02.2017 / 13:21
1

I know the question has already been answered, but for those who need to pick up the Portuguese language day on systems where they can not change the language, you can use a function like this:

// Se a variável $minhadataYmdHis não for passada pra função, pega data e hora atual do sistema
function diaSemanaPorExtenso($minhadataYmdHis=0)
{
    if($minhadataYmdHis==0)
    {
        $now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
        $minhadataYmdHis = $now->format('Y-m-d H:i:s');
    }

    $diaSemanaN= date("w", strtotime($minhadataYmdHis));

    switch($diaSemanaN)
    {
        case 0:
        $diaSemana="Domingo";
        break;
        case 1:
        $diaSemana="Segunda-feira";
        break;  
        case 2:
        $diaSemana="Terça-feira";
        break;  
        case 3:
        $diaSemana="Quarta-feira";
        break;
        case 4:
        $diaSemana="Quinta-feira";
        break;  
        case 5:
        $diaSemana="Sexta-feira";
        break;          
        case 6:
        $diaSemana="Sábado";
        break;              
    }
    return $diaSemana;
}

I took this function from a simple class for formatting and calculating dates that I use and maintain from time to time:

DateHelper.php:

link

    
20.02.2017 / 14:27