CodeIgniter Forums
get textbooks Published between YEAR provided[publication_date] and today - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: get textbooks Published between YEAR provided[publication_date] and today (/showthread.php?tid=70010)



get textbooks Published between YEAR provided[publication_date] and today - lsepolis123 - 02-08-2018

       

// 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




RE: get textbooks Published between YEAR provided[publication_date] and today - InsiteFX - 02-08-2018

If your passing a time reference to it then it should be a DATETIME field.


RE: get textbooks Published between YEAR provided[publication_date] and today - lsepolis123 - 02-09-2018

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???


RE: get textbooks Published between YEAR provided[publication_date] and today - salain - 02-09-2018

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"]);