skip to Main Content

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();
}

        

2

Answers


  1. 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();
    }
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search