PHP date AND time based condition

Here’s what I want to do:

If the date is Thu 23rd July 2009 and the time is greater than or equal to 05:00PM then a message is displayed. Otherwise nothing happens.

I’ve got this:

$d=date("D jS F Y");
if ($d=="Thu 23rd July 2009")
echo "It works!";

But I can’t for the life of me figure out how to include the time in this script, so that an echo takes place if it is a certain date AND time.

I also tried this:

$d=date("D jS F Y g:iA");
if ($d=="Thu 23rd July 2009 02:00PM")
echo "It works!";

But nothing happens - I think I need to have “>=” (Greater than or equal to) somewhere, especially for the time.

Would appreciate any helps guys.


if(time() >= mktime(17, 0, 0, 7, 23, 2009))


If the current time is greater than 23rd july 2009 @ 5pm

Whoa, that’s gotta be the fastest reply ever! Cheers for this :slight_smile:

Is the following correct? As I can’t seem to get it to display a message to show it works (it’s after 2pm (14:00) over here in the UK):

if(time() >= mktime(14, 0, 0, 7, 23, 2009)) {
echo "It works!";

As you’ve probably guessed, I’m no PHP guru like yourself…

Cheers again

Is your server based in the UK? Try the following to see what time the server thinks it is:

echo date('H:i');

Ah, spot on, turns out the server time is actually 13.11 so changed time to reflect this (13) and volia, works perfectly!

Guys, thanks so much, saved me a lot of headaches! :slight_smile:

Really appreciated so thanks again!

You’re welcome :slight_smile: