Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kenmasters/d58c1900e247309a93c571806dc1b279 to your computer and use it in GitHub Desktop.
Save kenmasters/d58c1900e247309a93c571806dc1b279 to your computer and use it in GitHub Desktop.
LARAVEL CARBON DATE FROM FORMAT
CODE INPUT:
Route::get('sample', function(){
$date = '06-28-2021'; //@fromFormat" m-d-Y
$date2 = Carbon::createFromFormat('m-d-Y', $date)->format('Y-m-d'); //@toFormat" Y-m-d
return response()->json(['from:' => $date, 'to' => $date2]);
});
RESULT:
{
"from:": "06-28-2021",
"to": "2021-06-28"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment