Mysql timestamp to date

1034 0 0 0

Last Updated : 2024-04-23 08:00:29

To convert a mysql date to an ordinary date you can use the following snippet

//MYSQL  timestamp to date 
date("Y-m-d", strtotime($item->date)

{{ strftime("%d %b %Y",strtotime($user->created_at)) }}


In other situation, you will need to convert a timestamp to match and be inserted to a mysql , Here is a simple note and solution:


 //Transform timestamp to a mysql date
$allowedDate = date('Y-m-d H:i:s', time()-$allowedMonths*30*24*60*60);

//Now you can use this with your model queries
$oldRecords = FeedvisitstatusModel::where('view_date', "<", $allowedDate)->delete();

Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .