Using Carbon to return a human readable datetime difference

By default, Eloquent will convert the created_at, updated_at, and deleted_at columns to instances of Carbon. So, your code should be just like this: $comment->created_at->diffForHumans(); It’s very cool. It’ll produce string like 2 minutes ago or 1 day ago. Plurar or singular, seconds, minutes, hours, days, weeks, or years, it runs automatically. I’ve tested it on … Read more

Convert String to Carbon

You were almost there. Remove protected $dates = [‘license_expire’] and then change your LicenseExpire accessor to: public function getLicenseExpireAttribute($date) { return Carbon::parse($date); } This way it will return a Carbon instance no matter what. So for your form you would just have $employee->license_expire->format(‘Y-m-d’) (or whatever format is required) and diffForHumans() should work on your home … Read more

Calculate difference between two dates using Carbon and Blade

You are not following the example from the Carbon Documentation. The method Carbon::createFromDate() expects 4 parameters: year, month, day and timezone. And you are trying to pass a formatted date string. If you want to create a Carbon object from a formatted date string you can use the constructor of the class just like this: … Read more

How to get Current Timestamp from Carbon in Laravel 5

You can try this if you want date time string: use Carbon\Carbon; $current_date_time = Carbon::now()->toDateTimeString(); // Produces something like “2019-03-11 12:25:00” If you want timestamp, you can try: use Carbon\Carbon; $current_timestamp = Carbon::now()->timestamp; // Produces something like 1552296328 See the official Carbon documentation here.

PHP Carbon, get all dates between date range?

As of Carbon 1.29 it is possible to do: $period = CarbonPeriod::create(‘2018-06-14’, ‘2018-06-20’); // Iterate over the period foreach ($period as $date) { echo $date->format(‘Y-m-d’); } // Convert the period to an array of dates $dates = $period->toArray(); See documentation for more details: https://carbon.nesbot.com/docs/#api-period.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)