Question

I have a database that store transaction logs, I would like to count all of the logs for this current week only. Date is stored in Unix

Get the current week starting from Monday to today.

$week = mktime(0, 0, 0, date('n'), date('j'), date('Y')) - ((date('N')-1)*3600*24); 

MySQL query

$q = 'SELECT count( distinct ID) as count FROM STATUS WHERE PERSON ='.$db->qstr($id).' AND DATE
(FROM_UNIXTIME(STATUS_DATE)) ='.$db->qstr($week);

can anyone advise me what I am doing wrong?

Was it helpful?

Solution

You could use:

WHERE DAYOFWEEK(CURDATE())>=DAYOFWEEK(WORK_ORDER_STATUS_DATE)

or you could use:

WHERE WEEK(CURDATE())=WEEK(WORK_ORDER_STATUS_DATE)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top