I would like to format "regDate" to 'dd/mm/YYYY' from 'YYYY/mm/dd'. Appreciate any help. Thanks.
if ($request->keyword != "") {
$students = Student::where
("name","LIKE","%" . $request->keyword . "%")
->orWhere("nric","LIKE","%" . $request->keyword . "%")
->orWhere("address","LIKE","%" . $request->keyword . "%")
->orWhere("telNo","LIKE","%" . $request->keyword . "%")
->orWhere("email","LIKE","%" . $request->keyword . "%")
->orWhere("regDate","LIKE","%" . $request->keyword . "%")
->get();
}
CodePudding user response:
Please set your date format like below and check again.
date('d/m/Y', strtotime($request->keyword));
if ($request->keyword != "") {
$students = Student::where
("name","LIKE","%" . $request->keyword . "%")
->orWhere("nric","LIKE","%" . $request->keyword . "%")
->orWhere("address","LIKE","%" . $request->keyword . "%")
->orWhere("telNo","LIKE","%" . $request->keyword . "%")
->orWhere("email","LIKE","%" . $request->keyword . "%")
->orWhere("regDate","LIKE","%" . date('d/m/Y', strtotime($request->keyword)) . "%")
->get();
}
CodePudding user response:
if (DateTime::createFromFormat('d/m/Y', $request->keyword) === true) {
$request->keyword = Carbon::createFromFormat('d/m/Y', $request->keyword)->format('Y-m-d')
}
if ($request->keyword != "") {
$students = Student::where
("name","LIKE","%" . $request->keyword . "%")
->orWhere("nric","LIKE","%" . $request->keyword . "%")
->orWhere("address","LIKE","%" . $request->keyword . "%")
->orWhere("telNo","LIKE","%" . $request->keyword . "%")
->orWhere("email","LIKE","%" . $request->keyword . "%")
->orwhereDate("regDate","=","$request->keyword")
->get();
}
Check value if date you can convert to your format and then you can send query