简体   繁体   中英

Change Date format using Carbon

I am using Laravel framework and for date conversion using Carbon package

I am unable convert date format to mysql format.I have following code

$request->event_start_date will have 25/08/2017

print_r(carbon::parse($request->event_start_date));

when $request->event_start_date is 03/08/2017 then it will print as

Carbon\Carbon Object( [date] => 2017-03-08 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC)

But if date is 25/08/2017 then it will throw erorr as

"G:\\XAMPP\\htdocs\\myproject\\vendor\\nesbot\\carbon\\src\\Carbon\\Carbon.php" line : 291 message : "DateTime::__construct(): Failed to parse time string (25/08/2017) at position 0 (2): Unexpected character"

need to convert 25/08/2017 to Mysql date format.I have tried a lot to fix this .finaly posted here so that i get some help from you

Thanks

Carbon extends PHP's native DateTime class, so you can use the same createFromFormat method:

$dateString = '25/08/2017';
$dateObject = \Carbon::createFromFormat('d/m/Y', $dateString);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM