2018-11-29 07:22
浏览 126


I have selected two dates in a date range picker and stored them in one data base column but it only stores one date, like: 0000-00-00. I can't store two dates in one column so I want to split this string into two variable by hyphen (-).

This is my date range function:

   $(function () {

       //Initialize Select2 Elements

     //Date range picker


This is my date insert code:

'bilty_date_range'      => date('y-m-d',strtotime($bilty_date_range)),

I am selecting the date like this: enter image description here

The backend result is like this: 11/07/2018 - 12/25/2018 .

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

  • doulun1939 2018-11-29 07:30

    String split functions are available in both Javascript and PHP.

    In php, you can just use

    $arr = explode("-", $str);
    $date_start = $arr[0];
    $date_end = $arr[1];

    As a matter of fact, you don't even need to store both into two seperate variables after you got them in an array. Just pass $arr[0] and $arr[1] when storing them into Database.


    'date_start'      => date('y-m-d',strtotime($arr[0])),
    'date_end'      => date('y-m-d',strtotime($arr[1])),
    解决 无用
    打赏 举报

相关推荐 更多相似问题