IF Date equal s

Three hours now and I still have sussed this…can anybody help!! I am such a newbie!

I want to display either Coming up or You’ve missed it for an event.

I need to set the event variable (the date and time of the event) and then check to see if the date and time have past or are coming up. I’ve ended up with this from I just don’t know where, and it still not working!

[php]<?php
$event3 = date(‘12-10-2013 10:00’);
if(time < $event3){

echo ‘Coming up’;}
else {
echo ‘You’ve missed it’;
}
?>[/php]

Please help if you are able and be kind to me! It been a terrible morning!

[php]<?php
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);
date_default_timezone_set(‘Europe/Oslo’);

$event3 = date(‘12-10-2013 14:00’);
echo date(‘d-m-Y H:i’, time()) > $event3 ? ‘You’ve missed it’ : ‘Coming up’;[/php]

Find your timezone here: http://us3.php.net/manual/en/timezones.php

Jim Thank you. I thin that has worked although I was unsure of line 2,3 & 4 as I am using Wordpress and this code is page/post specific and I do wish I understood it fully, I thank you for your time.

John

These lines are for developing environments only, do not use in a production environment.
[php] ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

Could you please explain what line 7 is saying?

Hello Milbra,

Line 7 uses a PHP technique called ternary conditional operator shorthand. It’s basically:

[php]($cond == TRUE) ? ‘Do This…’ : ‘Do That…’[/php]

Which translates to:

[php]if($cond == TRUE) {
‘Do This…’;
} else {
‘Do That…’;
}[/php]

What line 7 is saying is that if the date formatted by the date() function is greater (or basically later) that the date format stored in the variable $event3, echo “You’ve missed it” otherwise echo “Coming Up”. I hope I explained it to you so you can understand fully.

Cheers!

You did… thanks, jacster.

Sponsor our Newsletter | Privacy Policy | Terms of Service