![]() |
Getting last months data from database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Getting last months data from database (/showthread.php?tid=66025) |
Getting last months data from database - doomie22 - 08-25-2016 Hi there, I am trying to work out how I can get the previous months results from my database. This is what I have so far but I just cannot figure out what should be in the where line. PHP Code: public function get_last_month(){ Can anyone help please? Thanks, Doomie RE: Getting last months data from database - mubbi.qureshi - 08-25-2016 (08-25-2016, 08:34 AM)Hi Doomie22,here is the solution for getting last month data: Wrote: RE: Getting last months data from database - Wouter60 - 08-25-2016 First, try to get the month number AND year from the previous month. PHP Code: $pm = (int) date('n', strtotime('-1 months')); Now you're ready to build your query: PHP Code: public function get_last_month(){ Hope this will help. RE: Getting last months data from database - doomie22 - 08-25-2016 (08-25-2016, 11:39 AM)Wouter60 Wrote: First, try to get the month number AND year from the previous month. This worked perfectly. Thank you so much. |