Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!