Print full day of the week adding one day

Asked

Viewed 207 times

2

I am trying to print the full day of the week (Monday, Tuesday...) of a date returned from the database. However, it is always printing with a day less, for example, instead of printing Monday, 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 'Monday' and so on.

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

echo JText::sprintf(JHTML::_('date',  $item->data_inicio, JText::_("l, ")));
  • Could you add the question an example of date you’re trying?

  • What is this component you are using?

  • 1

    The company in which I work paid another company to develop the site in Joomla a few years ago and even today we are trying to fix some bugs, this is an example. It is an agenda component that has already been installed on the site.

  • Try removing parameter '1' as argument from Jtext().

2 answers

3


The function date 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, ")));
  • 1

    Perfect, now yes it worked 100%, thank you so much for your help.

  • 1

    @Leandrosilva see the change, strtotime need the date in another format to work 100%.

  • Dough, for now putting only strtotime is working, then I will do this scheme of transforming the date from YYYY-DD-MM to YYYY-MM-DD, thanks again for the help.

1

I know the question has already been answered, but for those who need to take the day of the week in Portuguese in systems where there is no way to 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 I use and do maintenance from time to time:

Datehelper.php :

http://pastebin.com/WJDbBLF0

  • Very good solution too, good to know, knowledge is never enough.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.