Welcome Guest, Not a member yet? Register   Sign In
SOLVED: Only show DB result from last month?
#1

[eluser]Joakim_[/eluser]
Hi.

I have some hard times showing only the last month entries from the DB.

Code:
$this->db->where('entry_date', date("m/d/Y",strtotime("last month")));

This code works but only show the entries with the same date as the current one. Somebody know how to make it show all entries from last month with any date? i have tried replacing the "d" and "Y" with "*" and even zeros but none of it work.


Any help are extremely appreciated! Thanks Smile
#2

[eluser]Michael Wales[/eluser]
Code:
$this->db->get_where('jobs', array('MONTH(created_on)' => date('m', strtotime('last month'))));
#3

[eluser]Randy Casburn[/eluser]
Here it is directly from MySQL manual page:

Select results occurring within the last 30 days:
Code:
WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col

Here's the reference:
[url http://dev.mysql.com/doc/refman/5.0/en/d...tions.html]
MySQL Manual Page
[/url]
#4

[eluser]Joakim_[/eluser]
It works! Thank you! Smile

[quote author="Michael Wales" date="1215370469"]
Code:
$this->db->get_where('jobs', array('MONTH(created_on)' => date('m', strtotime('last month'))));
[/quote]
#5

[eluser]Joakim_[/eluser]
Thank you a lot. I will check out that too.

[quote author="Randy Casburn" date="1215371084"]Here it is directly from MySQL manual page:

Select results occurring within the last 30 days:
Code:
WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col

Here's the reference:
[url http://dev.mysql.com/doc/refman/5.0/en/d...tions.html]
MySQL Manual Page
[/url][/quote]




Theme © iAndrew 2016 - Forum software by © MyBB