: Use Carbon Function for date in laravel:
$bdate='Monday 26th December 2016';
$temp_date=Carbon::createFromFormat('Y-m-d',Carbon::parse($bdate)->format('Y-m-d'));
dd($temp_date->toDateString()); //2016-12-26
$bdate='Thu Jan 05 2017 17:00:56
dd(Carbon::parse($bdate)->toDateString()); //2017-1-5
$bdate='Thu Jan 05 2017 17:00:56 GMT 0530';
dd(Carbon::parse($bdate)->toRfc1036String());
$bdate='2017-01-02';
$datetemp=carbon::parse($bdate)->format('l jS \\of F '); //"Monday 2nd of January "
$bdate='2017-01-07 08:38:01';
dd(Carbon::parse($bdate)->format('h:i')); //8:38
$bdate = str_replace('/', '-', $request->input('birthdate'));
$generaldetails->birthdate = Carbon::createFromFormat('d-m-Y', $bdate)->toDateTimeString();
$bdate = str_replace('/', '-', $patientlist->birthday);
$bdt = Carbon\Carbon::parse($bdate)->format('Y-m-d');
$cdate = Carbon\Carbon::parse(Carbon\Carbon::now())->format('Y-m-d');
$ccdat = Carbon\Carbon::createFromFormat('Y-m-d', $cdate)->toDateTimeString();
?>
@if($bdate == '01-01-1970')
{{''}}
@else
{{Carbon\Carbon::parse($bdt)->diffInYears(Carbon\Carbon::parse($ccdat))}}
@endif
Route::get('/ShowDateDemo', ['as' => 'ShowDateDemo', 'uses' => 'CarbonControllerDemo@ShowDateDemo']);
//age
//15/12/1983 to 1983-12-15 //
namespace App\Http\Controllers;
use carbon\Carbon;
Class CarbonControllerDemo extends Controller
{
public function ShowDateDemo()
{
$dateset='2014-2-2';
$dateFormate=Carbon::createFromFormat('Y-m-d',$dateset)->toDateTimeString(); // use for set formate
//dd($dateFormate);
// @if(Carbon\Carbon::parse($dateFormate)->format('d/m/Y') == Carbon\Carbon::parse($currentdate)->format('d/m/Y')) compare two dates in blade file
//{{ Carbon\Carbon::parse($reasondata->start_date)->format('d/m/Y') }} //Print date in blade file
/* get Age in controller
$current = Carbon::now();
$futuredate =new Carbon('1991-05-22');
dd($futuredate->diffInYears($current)); //25
dd($futuredate->diffForHumans($current)); //25 years ago
*/
/* get Age in blade file
$bdate = str_replace('/', '-', $patientlist->birthday);
$bdt = Carbon\Carbon::parse($bdate)->format('Y-m-d');
$cdate = Carbon\Carbon::parse(Carbon\Carbon::now())->format('Y-m-d');
$ccdat = Carbon\Carbon::createFromFormat('Y-m-d', $cdate)->toDateTimeString();
?>
@if($bdate == '01-01-1970')
{{''}}
@else
{{Carbon\Carbon::parse($bdt)->diffInYears(Carbon\Carbon::parse($ccdat))}}
@endif
*/
/* return redirect()->action('PersonnelsController@personnelDetail'); // return redirect()->route('viewPersonnelInfo')
echo asset('images/photo1.jpg');
echo secure_asset('images/photo1.jpg');
$RoutPath = route('doctor',1);
echo $RoutPath;
echo url()->previous(); //previous url
echo url()->full();
echo url()->current();
echo secure_url('doctor/showDoctorDetails');
echo secure_url('doctor/showDoctorDetails',1);
*/
}
}
//$carbon = new Carbon(); // $carbon ::now(); Europe/London,America/Vancouver
// $carbon = Carbon::now('Europe/London'); // date time timezone_type,timezone
//dd($carbon);
$carbon = Carbon::now(-1);
// dd($carbon);
$todaydate = Carbon::today()->toDateTimeString(); //display only date and time
// dd($todaydate);
$dateformate = str_replace('-', '/',$todaydate);
// dd($dateformate);
$dateFormate=Carbon::createFromFormat('Y-m-d','2014-2-2')->toDateTimeString(); // use for set formate
dd($dateFormate);
//dd(Carbon::parse($todaydate)->addWeeks(1));// Insert week // echo (new Carbon($todaydate))->addWeeks(1);
$current = Carbon::now();
//dd($current);
$dt = $current->subdays(6); //subtract days
//dd($dt);
$futuredate = $current->addMonth();
//dd($futuredate);
//dd($current->diffInDays($futuredate));
$insertday = $current->addDays(1); //add days
//dd($insertday);
No comments:
Post a Comment