PHP

  minte9
REMEMBERS




Last update:   28-03-2022

Carbon

An international PHP extension for DateTime.
 
/**
 * The Carbon class is inherited from the PHP DateTime class.
 * 
 * composer require nesbot/carbon
 */

require __DIR__ . '/vendor/autoload.php';

use Carbon\Carbon;

/**
 * next
 */
$now = Carbon::now();
$dt = Carbon::parse($now);
echo $dt->hour . "\n";

$date = $now->add(1, 'day');
echo $date->isoFormat('dddd D') . "\n"; 
    // Tuesday 29
    
$date = $now->add(1, 'month');
echo $date->isoFormat('YYYY-MM-DD') . "\n"; 
    // 2022-04-29

/**
 * timezone
 */
$now = Carbon::now();
$dt = Carbon::parse($now);
echo $dt->timezone . "\n"; 
    // Europe/Helsinki
echo $dt->hour . "\n";
    // 16

$nowLondon = Carbon::now('Europe/London');
$dt = Carbon::parse($nowLondon);
echo $dt->hour  . "\n"; 
    // 14

DateTime

Date and time from the server where your PHP scripts are running.
 
// Add time to get a future date

$date = new DateTime();
$format = "Y-m-d";

echo $date->format($format) . "\n";
    # 2021-12-20

$date->modify("+12 days");
echo $date->format($format) . "\n";
    # 2021-01-01

$date->modify("+31 days");
echo $date->format($format) . "\n";
    # 2021-02-01

$date->modify("+31 days");
echo $date->format($format) . "\n";
    # 2021-03-04

Questions     github Composer
Faker
        A B C D E F
🔔
1/1