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 + 30 > days) or a message is echoed. > > I'm finding this difficult to do, but I'm coming from an ASP background. > > 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. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php