If date is past

Joined: 11/28/2008

I'm trying to make an if() statement where something will happen if $launchtime is past $servertime.

<?php
   $servertime
= date('m/d/Y h:i:s A');
  
$launchtime = "01/01/2008 12:00:00 AM";
?>

I tried this

<?php
  
if($servertime >= $launchtime) {}
?>

But it only works if the $servertime is larger than the $launchtime. I need it so that it could be any day and time, not one number larger than the other. Understand? It's hard to explain, sorry.

Any help would be appreciated. Thanks!

Joined: 12/01/2008
Simple Fix

Joe,

All you need to do is this:

<?php
   $servertime
= strtotime(date('m/d/Y h:i:s A'));
  
$launchtime = strtotime("01/01/2008 12:00:00 AM");
?>

That should take care of your issue. If not let me know.

I am a Conservative Christian, Husband, Father of 2, Director of Operations for a Fort Wayne website design company (Cirrus ABS), Front-end Web Designer/Developer, and a Full Time Geek. Find older articles about ever

Joined: 11/28/2008
What does strtotime() do? It

What does strtotime() do? It should work with what I'm doing here?:

<?php
  
if($servertime >= $launchtime) {}
?>

Joined: 12/01/2008
String to time converts it to

String to time converts it to unix timestamp which are numbers. Thus it can logical manipulation after that.

I am a Conservative Christian, Husband, Father of 2, Director of Operations for a Fort Wayne website design company (Cirrus ABS), Front-end Web Designer/Developer, and a Full Time Geek. Find older articles about ever

Joined: 11/28/2008
That makes sense. Thanks, it

That makes sense. Thanks, it did work!

Joined: 12/01/2008
No problem. (you can also

No problem.

(you can also thank TJ as I bounced it off him too)

I am a Conservative Christian, Husband, Father of 2, Director of Operations for a Fort Wayne website design company (Cirrus ABS), Front-end Web Designer/Developer, and a Full Time Geek. Find older articles about ever

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
I love code in the forums...

I love seeing code in the forums :)

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

Joined: 09/25/2008
Just for fun...

Just for fun, strtotime converts a string to an number representing the number of seconds since January 1 1970 00:00:00 GMT (called the Unix epoch) so it takes into account the days and years as well as the hours and minutes.

Here's a warning from the php.net manual:
The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.