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 () {
        useCurrent: false,
        format: 'Y-MM-D H:mm',
        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

  • 写回答

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

            useCurrent: false,
            minDate: moment()
            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');
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 Spring MVC项目,访问不到相应的控制器方法
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on发生意外错误: 5无法连接到 MQTT 代理,如何解决?
  • ¥15 关于#genesiscsheel#的问题,如何解决?
  • ¥15 Android aidl for hal
  • ¥15 STM32CubeIDE下载程序报错
  • ¥15 微信好友如何转变为会员系统?(相关搜索:小程序)
  • ¥15 c# 直接使用c++ 类库文件
  • ¥15 一个主机电脑有两个显示器,当前有两个软件主体是网页html打包的exe程序,如何通过cmd命令bat同时打开软件一个在主屏幕显示,另外一个软件在2副屏幕上显示