View Single Post
Old 07-05-09, 09:15 PM   #5
Baph
Guest
 
Posts: n/a
Default Re: PHP / MySQL coders out there, script help

Quote:
Originally Posted by TSM View Post
Ie i have a table of log entries that has a list of image downloads that the client has done, client X has a limit of 50 images per month/week/quarter/year but the start of each period has to be keyed to their periodstart date, ie startperiod is 2009-01-31, if user had yearly limits on then the start date would be 2008-01-31, if it was monthly it would be 2008-12-31, if it was weekly then it would be 2009-01-24.
Code:
SELECT DATE_ADD(FROM_UNIXTIME($n_start_date), INTERVAL 1 YEAR);
That would return the date 1 year from $n_start_date (in Unix timestamp format).

Code:
SELECT DATE_ADD(FROM_UNIXTIME($n_start_date), INTERVAL 1 MONTH);
That would return the date 1 month from $n_start_date (again, in Unix timestamp).

My original post, whilst a little obscure, was just really saying to use the MySQL Date_Add() function to calculate date differences. Take a look at the MySQL documentation for DATE_ADD() - it'll calculate everything much easier for you.

EDIT: MySQL DATE_SUB() for subtractions.

If you want, it could even be built into a nested statement and all executed within the DB to return the number of images per period, then use mysql_num_rows() to see if they're over the limit.

Last edited by Baph; 07-05-09 at 09:18 PM.
  Reply With Quote