-4

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

Ami
  • 1
  • 2

2 Answers2

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.

muya.dev
  • 966
  • 1
  • 13
  • 34
Anuj
  • 41
  • 3
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