PHP code example of daun / datetime-carbon-format

1. Go to this page and download the library: Download daun/datetime-carbon-format library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

daun / datetime-carbon-format example snippets


// $page->date is a Datetime field
// Output format: j/n/Y

echo $page->date;                    // 20/10/2020
echo $page->date->add('7 days');     // 27/10/2020
echo $page->date->format('l, F j');  // Monday, October 20
echo $page->date->year;              // 2020
echo $page->date->diffForHumans();   // 28 minutes ago

// Date field with data
$page->date->timestamp;    // 1578870000
$page->date->isset;        // true
$page->date->year;         // 2020
$page->date->format('j');  // 20

// Empty date field
$page->date->timestamp;    // null
$page->date->isset;        // null
$page->date->year;         // null
$page->date->format('j');  // null

// Create a new Carbon instance
$datetime = wire()->carbon->createFromTimestamp($timestamp);