Welcome Guest, Not a member yet? Register   Sign In
get textbooks Published between YEAR provided[publication_date] and today
#1

       

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

Reply
#2

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 )
Reply
#3

(This post was last modified: 02-09-2018, 01:03 AM by lsepolis123.)

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???
Reply
#4

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

Reply




Theme © iAndrew 2016 - Forum software by © MyBB