This topic is locked
[SOLVED]

 list records form last week , lasta month

2/27/2014 12:18:19 AM
PHPRunner General questions
jgeorgiou author

I have a table , with a datefield

How can i make it shows (custom view to put it ready on menu) only last week and last month records? I mean , ready for the user , not to make him use search/filter byhimself
thanks

Sergey Kornilov admin 2/27/2014

You need to add a WHERE clause to SQL query of those custom views. Details depend on what database do you use.
Here are a few examples for MySQL:

http://stackoverflow.com/questions/2090221/mysql-query-to-get-all-rows-from-previous-month

http://stackoverflow.com/questions/6089960/mysql-query-to-select-data-from-last-week

jgeorgiou author 3/1/2014



You need to add a WHERE clause to SQL query of those custom views. Details depend on what database do you use.
Here are a few examples for MySQL:

http://stackoverflow.com/questions/2090221/mysql-query-to-get-all-rows-from-previous-month

http://stackoverflow.com/questions/6089960/mysql-query-to-select-data-from-last-week


Hi Sergey

I 've tried these solutions but sql query in PHPrunner 7.1 makes error message about where
table: datereg , field2 , field3 , field4 , ...etc
I've tried the (last week list)
WHERE datereg >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY

AND datereg < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
or
WHERE

WEEK (datereg) = WEEK( current_date ) - 1 AND YEAR( datereg) = YEAR( current_date );
----------------------------------------------------------------------------

I've tried the (last month list)
WHERE YEAR(datereg) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)

AND MONTH(datereg) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
or
WHERE datereg > (NOW() - INTERVAL 1 MONTH);
this last doesn't make error message but doesnt work!...it show all records ..even older than 1 month
---------------------------------------------------------------------
Can you help me fix this query to run?

Sergey Kornilov admin 3/1/2014

Lets proceed step by step. What error message each query produces?

J
jackheitzer@gmail.com 3/2/2014

Hi all,
I use these lines in "list page; before sql query:
(FromDate is the name of your "date field"'
//Last week
$week = date("W");

$strWhereClause = whereAdd($strWhereClause,"week(FromDate,1) = '". date("W")."'-1");

$strWhereClause = whereAdd($strWhereClause,"year(FromDate) = '". date("Y")."'");
// Last month
$strWhereClause = whereAdd($strWhereClause,"month(FromDate) = '". date("m")."'-1");

$strWhereClause = whereAdd($strWhereClause,"year(FromDate) = '". date("Y")."'");
Works for me,
Jack

jgeorgiou author 3/6/2014



Hi all,
I use these lines in "list page; before sql query:
(FromDate is the name of your "date field"'
//Last week
$week = date("W");

$strWhereClause = whereAdd($strWhereClause,"week(FromDate,1) = '". date("W")."'-1");

$strWhereClause = whereAdd($strWhereClause,"year(FromDate) = '". date("Y")."'");
// Last month
$strWhereClause = whereAdd($strWhereClause,"month(FromDate) = '". date("m")."'-1");

$strWhereClause = whereAdd($strWhereClause,"year(FromDate) = '". date("Y")."'");
Works for me,
Jack


Thanks all for your response

Best solution for my case is this! .... thanks jackheitzer@gmail.com

One more question .... can i manipulate the day (last day instead of last week , month) with in "list page; before sql query:" way?