I want to get 1 year old data from database till current date but from the beginning of month.if today is 25-08-2016 i have to get data from 01-08-2015 till now
Asked
Active
Viewed 95 times
-4
-
3It helps to post code that you've tried. – P. Gearman Aug 25 '16 at 13:19
-
2Please profide a [mcve] – Xorifelse Aug 25 '16 at 13:20
-
http://stackoverflow.com/questions/11808232/how-do-i-get-the-first-day-of-the-current-month (- interval 1 year) – Mike Aug 25 '16 at 13:20
-
2`select * from table where date >= DATE_SUB(NOW(),INTERVAL 1 YEAR);` – devpro Aug 25 '16 at 13:20
-
If i am logging in on 28-08-2016, i should get data from 01-08-2015 to 28-08-2016 – Ami Aug 25 '16 at 13:50
2 Answers
0
First find first day of the month link
$firstDateOfMonthLastYear = date('01-m-Y', strtotime('-1 years');
$today = date('d-m-Y');
Run Below query to get all data as per your requirement.
$query = "SELECT * from tbname where reportDate between ".$firstDateOfMonthLastYear." and ".$today." order by tbname.primary_key desc"
You need to replace tbname by your original table name. You need to replace tbname.primary_key by your table primary key.
0
In codeigniter try this
$where = "date >= DATE_SUB(NOW(),INTERVAL 1 YEAR)";
$this->db->where($where);

muya.dev
- 966
- 1
- 13
- 34
-
I got the answer ->where('admit_date >= CONCAT(LEFT(NOW() - INTERVAL 1 YEAR,7),"-01")') – Ami Aug 26 '16 at 05:37