类型错误: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)更多推荐
发布评论