Ok, this is how I finally managed to get it to work - I'm sure there are
other ways, but this works:

//Check to make sure the next eval date is more than 30 days away

$d1 = date('Y-m-d', strtotime($todays_date . '+30 day'));
$d2 = date('Y-m-d', strtotime($nextdate));


        echo "Sorry, your next evaluation date must be at least 30 days
away, Click BACK to continue.";

-----Original Message-----
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Tuesday, September 01, 2009 12:43 PM
To: David Stoltz
Cc: php-general@lists.php.net
Subject: Re: [PHP] Date +30 comparison

On Tue, 2009-09-01 at 12:19 -0400, David Stoltz wrote:
> I'm really struggling with dates in PHP. (Yes, I tried reading the
> manual)...
> Can someone provide code that does this:
> Takes current date, assigns it to a variable (let's say $today)
> Then adds 30 days to $today variable
> Takes a string ($nexteval) like '8/26/2009' and compare it to $today.
> The variable $nexteval must be greater than $today (which is today +
> days) or a message is echoed.
> I'm finding this difficult to do, but I'm coming from an ASP
> Any help appreciated.

PHP (like all languages I know) treats dates as numbers; and PHP
specifically uses seconds since January 1st 1970 (other languages
sometimes have different start points and can measure in milliseconds
instead). With this in mind, you can compare dates directly as you would
an integer, and the later date will be the higher value.

To add 30 days to a given date, you could use the date_add function
(http://uk2.php.net/manual/en/datetime.add.php ) which has various
formats you can use to add different time units.

Lastly, to turn a date like 8/26/2009, I would probably try to break it
down into it's component parts (maybe using explode('/', $string_date) )
and then using those values as arguments in a mktime() function. PHP
should automatically treat the values as integers if they are strings,
because like ASP, it uses loose typing on variables.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to