View Full Version : How to trim or sub a date variable?

02-23-2007, 05:08 PM

Im trying to figure out how to show tickets on my site thats older then 14 days, how do i do that? here are my codes

/* old_tickets */
$now_old = 'NOW()';
$sql_old = "SELECT * FROM `hesk_tickets` WHERE `dt`<= $now_old AND ";
$sql_old .= Categories();
$sql_old .= " AND `status`>=1 ";
$result_old = dbQuery($sql_old)
$all_old = dbNumRows($result_old);

At the moment it shows all tickets, if i replace this for an example :

$sql_old = "SELECT * FROM `hesk_tickets` WHERE `dt`<= '2007-01-23 11:48:03' AND ";

I can see that it only shows some tickets, older ones..that it should be.

But how do i trim the $now_old variable so that it automatic will be put 14 days older than just NOW() = todays date etc.:confused:

what im after is something like :

$now_old = 'NOW()'-14days :P

02-23-2007, 05:22 PM
Use something like this

$now_old = date('Y-m-d h:i:s', mktime(0,0,0,date("m")-2,date("d")-22,date("Y")));

Good luck!