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";
My Answer:
>challenge_start_date));__Check if todays date is after challenge start date_if ($date_now > $challengeStartDate) { echo "Challenge has started!";}_I believe the issue lies in the comparison of the two dates. You can try converting both dates to timestamps and then comparing them. Here is an updated version of the code:_Get todays date_$date_now = time();__Challenge start date_$challengeStartDate = strtotime($this->challenge_start_date);__Check if todays date is after challenge start date_if ($date_now > $challengeStartDate) { echo "Challenge has started!";}This should now correctly display the text if todays date is after the challenge start date.
Rate this post
5 of 5 based on 4616 votesComments