Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda