Convert string to date in Laravel
P粉270891688
P粉270891688 2023-09-07 11:41:49
0
1
684

I have a string representing a date. I want to store it in my database but the problem is that in my database the property is defined as date. How to correctly convert a string to a date so it can be stored in the database? This is how my string looks like: "fecha":"31 March 2023" . Thanks.

P粉270891688
P粉270891688

reply all(1)
P粉134288794

You can use the strtotime() function to convert any English text datetime description to a unix timestamp, and using the date() function you can format a unix timestamp. You can use both like this:

$date = date('Y-m-d',strtotime($string));

You can write it into a mutator, or you can check out the date conversion article in the documentation:

Date Conversion Document

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!