RE: -14 Days Ago

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cole,

I don't know the full context of how you need to do your date math. However,
what if, instead of selecting a bunch of data and putting it in an array in
PHP then checking to see if its older than 14 days you wrote your query to
pull only those records that are older than 14 days?

Something like (assuming MySQL):

mysql> select contentID, printDate from docmeta where TO_DAYS(NOW()) -
TO_DAYS(printDate) > 14;

The above query subtracts a column's value from today's date. If the
difference is greater than 14, it get pulled into the query. If you only
wanted records newer than 14 days, you would just flip the comparison
operator like so:

mysql> select contentID, printDate from docmeta where TO_DAYS(NOW()) -
TO_DAYS(printDate) < 14;

(I hope I got that right)

Anyway, from there, you could do whatever you need to do with the result set
programmatically inside of your PHP script. My hunch is that it might be a
little faster to do the date math in MySQL (or your db of choice) and just
work with the exact result set you want inside your script.

Hope this helps.

Rich



> -----Original Message-----
> From: Cole S. Ashcraft [mailto:csa@xxxxxxxxxxxxxxxxxx]
> Sent: Friday, October 08, 2004 2:36 PM
> To: php-db@xxxxxxxxxxxxx
> Subject:  -14 Days Ago
> 
> 
> 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
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux