I have small laravel project working on date conversion. I have date string that getting from request on format dd/mm/yyyy. Code and result show as below.
$request->stockupdate ;
// dd/mm/yyyy (02/05/2019)
Then I try to convert to yyyy-mm-dd using carbon.
$_stockupdate= Carbon::parse($request->stockupdate)->format('Y-m-d');
I got parse result as below.
2019/02/05 // Seem it is 2 Feb 2019 not 5 May 2019.
That's wrong, It should be 2019/05/02 instead. Any advise or guidance would be greatly appreciated, Thanks.
Your answer First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.
$date = Carbon\Carbon::parse($rawDate); well thats it. You'll now have a Carbon instance & you can format the date as you like using Carbon helper functions.
You can try this:
Carbon::createFromFormat('d/m/Y', $request->stockupdate)->format('Y-m-d')
You can try this :
$date = str_replace('/', '-', $request->stockupdate);
$newDate = date("Y-m-d", strtotime($date));
OR
Carbon::createFromFormat('d/m/Y', $request->stockupdate)->format('Y-m-d')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With