Abdallah Sakre
Abdallah Sakre

Reputation: 915

convert date/time format to a date only in a query

The following is the required date format :

$sel_date = date('Y-m-d');

But the created_at field has the full date/time format :

2019-10-15 16:14:18

I need to add to the query only the date by omitting the time, as below :

->where('created_at', $sel_date )

Upvotes: 0

Views: 75

Answers (3)

di3sel
di3sel

Reputation: 2012

Try this:

->whereDate('created_at', $sel_date)

Some documentation about additional where queries here.

Upvotes: 4

Bhavesh Parab
Bhavesh Parab

Reputation: 83

you can use date() function of mysql.

->where('date(created_at)', $sel_date )

Upvotes: 0

Shubham Narvekar
Shubham Narvekar

Reputation: 77

use the following

CAST("2017-08-29" AS DATE)

ref here

Upvotes: 0

Related Questions