• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get textbooks Published between YEAR provided[publication_date] and today


// 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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

So you mean the comparison is fine??? true / false

just convert field to DATETIME....
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

but as you know Publication dates of books is
month year
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???


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"]); 
A good decision is based on knowledge and not on numbers. - Plato


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.