I am in need of some help with a date comparison function of sorts.... I am looking for a way to accomplish the following: I have a date, in a variable, in MM/DD/YYYY format, this date is an expiration date. Im going to have this script run on cron and run once a day to run the check. What I would like it to do is get the expiration date in the variable and compare it to the current date, if the expiration date is 6 months from the current date I want it to email someone or perform some function. I am just too confused my date functions, strtotime, mktime, etc.
You should use timestamps to do this. time() will give you the current time in timestamp format, while mysql's UNIX_TIMESTAMP() will give you a date record in timestamp format.
Store the date in a variable then explode the date in array $ExpDateInArray = explode('/',$Expdate) $Day = $ExpDateInArray[0]; $Month = $ExpDateInArray[1]; $Year = $ExpDateInArray[2]; $TimeStampOfExpirationDate = mktime(0,0,0,$Day,$Month, $Year) You will get the expiration date timestamp And Also get the timestamp of current date. $CurrentDateTimeStamp = time(); if($CurrentDateTimeStamp > $TimeStampOfExpirationDate) then email the person