duanqianmou4661 2019-07-17 02:54
浏览 275
已采纳

如何将datetimepicker日期(bootstrap 4)格式转换为16/07/2019 10:00到mysql格式2019-07-16 10:00 with laravel(5.8)Carbon

hello friends I have a problem with the dates pause .. in my view I have a datetimepicker of (bootstrap 4) with the format 12/06/2019 12:00:00 and what I need is to pass it to the format that accepts mysql 2019-06-12 12:00:00

try to do it from js but it did not work

$(function () {
        $('#startdate').datetimepicker({
        useCurrent: false,
        format: 'Y-MM-D H:mm',
        autoclose:true,
        minDate: moment()
});

that's how I'm trying from my controller but it has given me an error :(

$promociones->fecha_inicio = Carbon::createFromFormat('Y-m-d H:i',$request->fecha_inicio)->toDateTimeString();
    $promociones->fecha_fin = Carbon::createFromFormat('Y-m-d H:i',$request->fecha_fin)->toDateTimeString();

the error the error

</div>
  • 写回答

4条回答 默认 最新

  • dtz46697 2019-07-17 22:48
    关注

    I had to investigate a lot and be trial and error but I managed to solve my problem ... thank you very much to all of you who helped me in providing ideas for my solution. Thanks for your help, it helped me a lot to solve my problem.

    I started fixing my datetimepicker so

    $('#startdate').datetimepicker({
            useCurrent: false,
            minDate: moment()
        });
        $('#enddate').datetimepicker({
            useCurrent: false,
            minDate: moment()
        });
    

    I had to remove the format I had given him....after that pass to the controller as some suggested to me ... pass the format that was receiving my input that is d / m / YH: m after that I passed the time zone of my country (in case there was a problem of dates) then I just had to pass the format with which I wanted to save it to the database in my case mysql by default accepts the format Ymd H: i ... and ready problem solved

    $promociones->fecha_inicio = Carbon::createFromFormat('d/m/Y H:i',$request->fecha_inicio,'America/El_Salvador')->format('Y-m-d H:i');
        $promociones->fecha_fin = Carbon::createFromFormat('d/m/Y H:i',$request->fecha_fin,'America/El_Salvador')->format('Y-m-d H:i');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接