Re: -14 Days Ago

From: Date: Fri, 08 Oct 2004 19:40:09 +0000
Subject: Re: -14 Days Ago
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-36704@lists.php.net to get a copy of this message
Cole S. Ashcraft wrote:
I am trying to see whether a data in an array pulled from a MySQL DB (YEARMONTHDATE) is older than 14 days ago. I am trying to do this in PHP. My code looks like: if($array['due'] <= $today - 14) { echo "<h5>Assignment In Void:</h5><br><h4>Assignments in the void are read-only"; require('footer.php'); exit; }. I am having problems with the math. How do I do a date subtraction without ending up with something like 20040994 (not a valid date)? Thanks, Cole
You need dates in timestamp format to subtract them. You can use the function strtotime() to convert to timestamp. For instance, you can use: $old_date = strtotime("2 weeks ago"); You then just need to convert the date from the database to a timestamp. strtotime will do something like: $db_date = strtotime("October 10 2004"); or $db_date = strtotime("10 October 2004"); But, I don't think it will do it your way. You may have to change the order of your string, as well as add spaces. Check the manual at http://us4.php.net/strtotime. IF the database value is in some kind of MySQL date format, you can perhaps retrieve it as a timestamp. MySQL has several DATE formats and date/time functions. Janet -- Janet Valade -- janet.valade.com

« previous php.db (#36704) next »