DEV Community

Raj
Raj

Posted on

How to change the timestamp column's format in Laravel?

If you want to compare the timestamp column value with today's date then first you need to change the format of the date-time value to the current date

*For example - *

find today's date data from the database table compare on the field created_at which is the timestamp column type.

$query->where(name, $name)->where(DB::raw("(DATE_FORMAT(date_time,'%Y-%m-%d'))"), 
Carbon::now()->format('Y-m-d'));
Enter fullscreen mode Exit fullscreen mode

Use DATE_FORMAT in DB::raw to convert the timestamp field into today's date and get data accordingly from the database.

Top comments (0)