php - How to count long days from one date to another date and insert to table of database using CI -
my table in mysql
i designed "survei_pohon" table , set 'submit_date' column has same values (default values, ex: 2013-02-28), , table below:
id survey_date submit_date long_day 1 2013-02-18 2013-02-28 10 2 2013-02-21 2013-02-28 10 3 2013-02-25 2013-02-28 10 "id" column 'integer' type, "survey_date" 'date' type, "submit_date" 'date' type, "long_day" 'integer' type.
this model : ` function olah(){ $tanggal_survei="select survey_date survei_pohon"; $tanggal_sekarang="select submit_date survei_pohon"; $lama_hari="select long_day survei_pohon"; $result = @mysql_query($tanggal_survei); $t = mysql_fetch_array($result); $results = @mysql_query($tanggal_sekarang); $u = mysql_fetch_array($results); $lama_hari = @mysql_fetch_array($lama_hari); $start = strtotime($t['tanggal_survei']); $end = strtotime($u['tanggal_sekarang']); $lama_hari = ($end - $start) / (60 * 60 * 24); $this->db->set('long_day', $lama_hari); $this->db->update('survei_pohon'); }
}?>`
my expectation "survei_pohon" table
id survey_date submit_date long_day 1 2013-02-18 2013-02-28 10 2 2013-02-21 2013-02-28 7 3 2013-02-25 2013-02-28 3 i'm guessing there wrong in model code. don't know how prepare code. i'm expecting help. help, hard me.
here's mysql solution update db.
update survei_pohon set long_day = submit_date - survey_date not sure need store field though since it's calculation of other fields -- leave ui purposes. in case, include in select statement:
select *, submit_date - survey_date long_day survei_pohon i know doesn't address how code, seems little easier.
here sql fiddle.
php mysql codeigniter strtotime
No comments:
Post a Comment