CodeIgniter Forums

Full Version: get textbooks Published between YEAR provided[publication_date] and today
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
       

// model function
// get textbooks Published between YEAR provided[publication_date] and today

if ($data_search["publication_date"]!='')    
           $this->db->where('publication_date >=', date("Y-m-d", mktime(0, 0, 0, 1, 1, $data_search["publication_date"])));


// you have any idea how compare dates???


// PHP my admin the field is Date field
publication_date   date

If your passing a time reference to it then it should be a DATETIME field.
So you mean the comparison is fine??? true / false

just convert field to DATETIME....
like
if ($data_search["publication_date"]!='')    
          $this->db->where('publication_date >=', date("Y-m-d H:i:s", mktime(0, 0, 0, 1, 1, $data_search["publication_date"])));

I like this picker
https://jqueryui.com/datepicker/#dropdown-month-year

but as you know Publication dates of books is
month year
eg
May 2016

In case in CRUD textbook procedures
in CREATE  put https://jqueryui.com/datepicker/#dropdown-month-year  but get Only eg month year // day=01, others 00:00:00
in SEARCH textbook put https://jqueryui.com/datepicker/#dropdown-month-year or something else put get only MONTH YEAR others 01 00:00:00

the comparison should be OK if using DATETIME???
Hi,

If you only need to verify the year then use MySQL YEAR() in your where clause


PHP Code:
$this->db->where('YEAR(publication_date) >='$data_search["publication_date"]);