Welcome Guest, Not a member yet? Register   Sign In
Getting last months data from database
#4

(08-25-2016, 11:39 AM)Wouter60 Wrote: First, try to get the month number AND year from the previous month.
PHP Code:
$pm = (int) date('n'strtotime('-1 months'));
$pmy = (int) date('Y'strtotime('-1 months')); 

Now you're ready to build your query:
PHP Code:
public function get_last_month(){
 
       $this->db->select('*');
 
       $this->db->from('test_table');
 
       $this->db->where('MONTH(date)'$pm);
 
       $this->db->where('YEAR(date)'$pmy);
 
       $query $this->db->get();
 
       return $query->result();
 
   
You need the year in case the current month is January!
Hope this will help.

This worked perfectly.

Thank you so much.
Reply


Messages In This Thread
RE: Getting last months data from database - by doomie22 - 08-25-2016, 11:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB