我正在尝试将出生日期从codeigniter形式插入到mysql数据库中,作为mysql日期格式,但是我却越来越喜欢这种格式“ 06/27/2018”。
我的模特如下
$birth_day = date('Y-m-d'); /* i want in this format*/
$birth_day = $this->input->post("b_day");
$data['b_day'] = $birth_day;
答案 0 :(得分:0)
使用DateTime
来更改Y-m-d
格式,如下所示:
$date_from_form = '06/27/2018';
/* Or do like this for post input
$date_from_form = $this->input->post("b_day");
*/
$date = DateTime::createFromFormat('m/d/Y', $date_from_form);
$birth_day = $date->format('Y-m-d');
//echo $birth_day;
$data['b_day'] = $birth_day;
程序输出
2018-06-27
答案 1 :(得分:0)
$birth_day = $this->input->post("b_day");
$data['b_day'] = date("Y-m-d",strtotime($birth_day));