douchigu1723 2018-11-29 07:22
浏览 128
已采纳

我想将一个字符串拆分为两个变量

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:

<script>
   $(function () {

       //Initialize Select2 Elements
     $('.select2').select2();

     //Date range picker
     $('#bilty_date_range').daterangepicker();

     });
 </script>

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.

    i.e.,

    'date_start'      => date('y-m-d',strtotime($arr[0])),
    'date_end'      => date('y-m-d',strtotime($arr[1])),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法