类型错误:DateTime ::

编程入门 行业动态 更新时间:2024-10-08 18:37:05
类型错误:DateTime :: __ construct()期望参数1为字符串,laravel中给出的对象(Type error: DateTime::__construct() expects parameter 1 to be string, object given in laravel)

我想要迟到的时候。 $ latetime1返回正确但$ latetime2与$ latetime1不同。 $ systemIntime值格式和$ inTime值格式相同。 但我在$ latetime2时遇到错误。 什么应该是正确的,请有人帮助我。 这是我的功能贝娄 -

public function update(Request $request, Attendance $attendance) { $attendance = Attendance::find($attendance->id); $inTime = $attendance->intime; // late time caculate $systemIntime = DB::table('schools') ->join('users', 'schools.id', '=', 'users.school_id') ->select('schools.intime') ->first(); $latetime1 = (new \DateTime($inTime))->format('H:i:s'); $latetime2 = (new \DateTime($systemIntime))->format('H:i:s'); $late = $latetime1->diff($latetime2);

I am trying to get late time. $latetime1 returning correct but $latetime2 not returning same as $latetime1. $systemIntime value format and $inTime value format are the same. But I am getting above error for $latetime2. What should be the correct one, please someone help me. Here is my function bellow -

public function update(Request $request, Attendance $attendance) { $attendance = Attendance::find($attendance->id); $inTime = $attendance->intime; // late time caculate $systemIntime = DB::table('schools') ->join('users', 'schools.id', '=', 'users.school_id') ->select('schools.intime') ->first(); $latetime1 = (new \DateTime($inTime))->format('H:i:s'); $latetime2 = (new \DateTime($systemIntime))->format('H:i:s'); $late = $latetime1->diff($latetime2);

最满意答案

你传递整个对象而不是它的属性,所以改变这个:

DateTime($systemIntime)

至:

DateTime($systemIntime->intime)

You're passing the whole object instead of its property, so change this:

DateTime($systemIntime)

To:

DateTime($systemIntime->intime)

更多推荐

本文发布于:2023-08-01 19:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1364647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   类型   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!