从datepicker到数据库的故障保存故障
目前,我有一个jQuery DatePicker,可以从日期和迄今为止添加一个。两个日期都从相同的输入中添加。我最终得到的格式是
$request->input('datepicker') // 07/29/2022 - 07/30/2022
我在日期案例中有一个start_at日期,这是时间戳,
这是我试图在保存到数据库之前试图更改格式的方式,
$firstDate = Carbon::parse(strtok($request->input('daterange'), '-'));
$startsAt = Carbon::createFromFormat('m/d/Y', $firstDate)->format('y-m-d');
则会给我以下错误
The separation symbol could not be found Unexpected data found. Trailing data
如果我删除碳, :: parse()我认为首先不是nessesary,而错误只是
Trailing data
由同一行引起的
Currently I have a jquery datepicker where it is possible to add a from date and to date. Both of the dates get added from the same input. The format I end up with is this
$request->input('datepicker') // 07/29/2022 - 07/30/2022
I have a starts_at date in the datebase which is a timestamp
This is how I am trying to change the format before saving it to the database
$firstDate = Carbon::parse(strtok($request->input('daterange'), '-'));
$startsAt = Carbon::createFromFormat('m/d/Y', $firstDate)->format('y-m-d');
The startsAt line is giving me the following error
The separation symbol could not be found Unexpected data found. Trailing data
If I remove the Carbon::parse() which I thought first was not nessesary the error is instead just
Trailing data
Caused by the same line
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
然后:
只需要确保输入始终采用该格式,因此您可能需要一个验证REGEXP,以确保其始终为“ M/d/y -m/y -m/d/y”格式
Then:
Just you need to be sure that the input is always on that format, so you probably need a validation regexp to ensure that always comes as "m/d/Y - m/d/Y" format