Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Show text after a date has passed

I am trying to get a simple line of text to appear if todays date is after another date.

I can either get it to appear on all pages or none, but I am unable to get it to display based on whether the challenge start date is before or after todays date. I believe it could be a date format issue, but everything I have tried has fallen short.

Here is my code:

Get todays date

$date_now = new dateTime();

Challenge start date

$challengeStartDate = date('dS F Y', strtotime($this->item->start_date));
echo '<!--' . strtotime('1970/1/1 00:00:00 +' . $validity) . '-->';

New text line

if ($challengeStartDate > $date_now) echo "New Text";
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

date() returns a string. With $challengeStartDate > $date_now it's like comparing if one string is bigger than the other (not sure if your dateTime handles that).

Your approach is otherwise fine. Just use timestamps to compare. time() gets you the time as a Unix timestamp:

$now = time();
if ($now > strtotime($this->item->start_date)) {
  // do your thing
}

Something like this is more what you need. Try it out.

over 4 years ago · Santiago Trujillo Relatório

0

I had the very same problem some time ago. All you need to do is store your local time in a database so it would be saved statically. Because in your example, both $challengeStartDate and $date_now will change and update simultaneously and you wiill always get the current pc time! Try storing it in a table or idk maybe sessions would help too.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda