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)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay