How to Change Date Format in Laravel 7/6? (ok)
https://www.itsolutionstuff.com/post/how-to-change-date-format-in-laravel-6example.html
<?php
use Illuminate\Support\Facades\Route;
use Carbon\Carbon;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('/test', function () {
$date = date('Y-m-d H:i:s');
echo $date;
echo "<br/>";
$newDate1 = Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('d-m-Y');
echo $newDate1; // "22-02-2020"
echo "<br/>";
$newDate2 = Carbon::createFromFormat('d-m-Y', $newDate1)->format('m/d/Y');
echo $newDate2; // "02/22/2020"
echo "<br/>";
$newDate3 = Carbon::createFromFormat('m/d/Y', $newDate2)->format('Y-m-d');
echo $newDate3; // "2020-02-22"
echo "<br/>";
$newDate4 = Carbon::createFromFormat('Y-m-d', $newDate3)->format('d/m/Y');
echo $newDate4; // "22/02/2020"
});
How to Change Date Format in Laravel 7/6?
PreviousHow to Increase Session Lifetime in Laravel? (ok)NextLaravel Disable Registration Route Example, login, verify, reset full (ok)
Last updated