Compare Two Datetimes?

Hi all, my boss wants me to have some content on our site for this afternoon and for it to tomorrow at 9.30am to change to something different - this is not an ongoing thing, just for today/tomorrow.

Not sure how I can do this? I know I would need an if/else statement but unsure of how to compare two dates? :slight_smile:

This is what I’ve managed to do so far but not working! Gerrr!


//Expiry date/time...
$exp_date = "03-03-11 11:25";

//Current date/time...
$todays_date = date('m-d-y g:i');

if($exp_date > $todays_date):
echo "Done";


comparing strings like that won’t work, especially leading with the month.

$exp_date = strtotime('2011-03-03 11:25:00');

if(time() >= $exp_date) {
    echo 'Done. New content here';

You can choose to use from a variety of date time functions. This is one example that uses two such functions:

// 03-03-11 11:25 pm
if (time() >= mktime(23, 25, 0, 3, 3, 2011)){
  // blah blah blah

Hey chaps, that’s perfect, all working beautifully now :slight_smile: Thanks again!