dongmei2957 2015-06-19 05:08
浏览 42
已采纳

如何在将数据发送到数据库时更改日期格式?

I am using jquery full calendar to show some booking details. I am inserting date into the database in ("yyyy-MM-dd") format.

But when i retrieve the title value from the calendar using var title=$("#calendar").fullCalendar('getView').title; it output as "June 2015". later i am using these two days for a comparison. Therefor i need to either send date into the database in "19 June 2015" format or convert title date value into "06 2015".

If anyone has a clear idea about this help me. Hope the problem is clear. I am using codeignier and i use the following cotroller method to send the data into the database.

function add_reservation() {
        $reservation_model = new Reservation_model();
        $reservation_service = new Reservation_service();

        $reservation_model->set_date_cal(trim($this->input->post('date', TRUE)));
       // $reservation_model->set_date(strtotime($this->input->post('date', TRUE)));
        $reservation_model->set_title(trim($this->input->post('selected_hall', TRUE)));
        $reservation_model->set_type(trim($this->input->post('selected_time', TRUE)));
        $reservation_model->set_description(trim($this->input->post('name', TRUE)));
        $reservation_model->set_advanced_payment_status(trim($this->input->post('optionsRadios', TRUE)));
        //$reservation_model->set_advanced_payment_status(trim($this->input->post('no', TRUE)));
        $reservation_model->set_paid_amount(trim($this->input->post('paid_amount', TRUE)));
        $reservation_model->set_fax(trim($this->input->post('fax', TRUE)));
        $reservation_model->set_telephone_number(trim($this->input->post('telephone', TRUE)));
        $reservation_model->set_address(trim($this->input->post('address', TRUE)));
        $reservation_model->set_menu_no(trim($this->input->post('selected_menu_number', TRUE)));
        $reservation_model->set_menu_price_per_plate(trim($this->input->post('menu_price', TRUE)));
        $reservation_model->set_is_deleted('0');

        $this->db->last_query();

        echo $reservation_service->add_reservation($reservation_model);


}

basically i want to change the format of the date which i am sending to the database as "19 June 2015"

  • 写回答

3条回答 默认 最新

  • duanfu3634 2015-06-19 05:38
    关注

    Don't change the MySQL format. Change your html OR keep every thing the same way it is now and use javascript to convert it to mysql format.

    var title=$("#calendar").fullCalendar('getView').title; // "June 2015"
    var d = new Date(title);
    var title = d.getFullYear() + "-" +( d.getMonth() + 1); // "2015-6"
    

    Now, you can compare. Let me know, if you are looking for something else.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)