Get the name of the month if the day of the event is the following month

Asked

Viewed 39 times

1

I have a website where shows the day of the event that takes place every Thursday. For this, I did so:

<?php
$data = date("w");
if($data == 4)
{
    echo "hoje";
}
else
{
    echo date('d', strtotime("next Thursday"));
}
?>

And as a result:

inserir a descrição da imagem aqui

The problem is that we are on 28/07 and the next event falls in August. How would I make it so that if the event is on a day that falls the following month, it automatically shows, otherwise it shows the current month?

  • 1

    Cite more examples!

  • 1

    Add how many days left and then decrease by the number of days last month. Ex.: 28+4=>32-31=1

1 answer

3


Hello.

You forgot the method: date('m', strtotime("next Thursday")) ;

Solution:

<?php
$data = date("w");
if($data == 4)
{
    echo "hoje";
}
else
{
    $mes = array("JAN","FEV","MAR","ABR","MAI","JUN","JUL","AGO","SET","OUT","NOV","DEZ");
    echo date('d', strtotime("next Thursday")) . " " . $mes[date('m', strtotime("next Thursday")) -1];
}
?>

Console:

01 AGO

Source: /a/26629/152846

I hope I’ve helped.

  • 1

    Perfect Maury. Thank you very much!

Browser other questions tagged

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