0

I tried this ,

$date = date('D, M dS Y g:i a', strtotime('2018-03-01 11:54:33'));
echo $date; // will print Thu, Mar 01st 2018 11:54 am

It worked , but I need same in search function ,

 $table->where("main.no", "like", "%$searchfield%")
       ->orWhere("date('D, M dS Y g:i a', strtotime('timestamp'))", "like", "%searchfield%")

Here , if i search fri in searchfield input box , its showing error as ,

Column not found: 1054 Unknown column 'Thu, Jan 01st 1970 5:30 am' in 'where clause' 

I think its trying to convert "fri" to date or something like that.

5
  • 1
    What is the name of your column where you search date?? Commented Feb 22, 2023 at 12:40
  • Your orWhere section does not make much sense as you try to compare a literal value with a pattern. Such a comparison does not have any bearing on what rows you select from the database. You need to have a field name as the first parameter of or Where. Commented Feb 22, 2023 at 12:45
  • 1
    strtotime is not a MySQL function, so cannot be used in the WHERE clause like that. date exists in MySQL, but you're calling it with the PHP definition, not the MySQL definition, so it's going to be very confused. Commented Feb 22, 2023 at 12:48
  • column name is timestamp @NIKUNJPATEL Commented Feb 22, 2023 at 15:57
  • try $table->where(function($query) use ($searchfield) { $query->where("main.no", "like", "%$searchfield%") ->orWhere(DB::raw("DATE_FORMAT(main.timestamp, '%a, %b %D %Y %h:%i %p')"), "like", "%$searchfield%"); }); Commented Feb 23, 2023 at 4:32

1 Answer 1

0

You can use this query for searching in orWhere condition:

$table->where(function($query) use ($searchfield) {
    $query->where("main.no", "like", "%$searchfield%")
          ->orWhere(DB::raw("DATE_FORMAT(main.timestamp, '%a, %b %D %Y %h:%i %p')"), "like", "%$searchfield%");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.