Carbon
An international PHP extension for DateTime. 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
Outdated
To upgrade a specific library, you'll first want to check if an update is needed. Composer will also update the transitive dependencies, but within the constraints (composer.lock).
cd github/php-pages/main/composer/carbon/
composer outdated
# Direct dependencies required in composer.json:
# nesbot/carbon 2.57.0 2.72.1 An API extension for DateTime ...
# Transitive dependencies not required in composer.json:
# symfony/polyfill-mbstring v1.25.0 v1.28.0 Symfony polyfill for the Mbstr...
Update Library
Composer updates to the latest version that satisfies the version constraints in composer.json
# composer.json
{
"require": {
"nesbot/carbon": "^2.72.1"
}
}
composer update nesbot/carbon
Update
This command updates all project's dependencies to their latest versions (constraints composer.json). It's a broader update and can potentially upgrade multiple packages, not just nesbot/carbon. This can lead to significant changes in your composer.lock file.
composer outdated
# Direct dependencies required in composer.json:
# Everything up to date
# Transitive dependencies not required in composer.json:
# symfony/polyfill-mbstring v1.25.0 v1.28.0 Symfony polyfill for the Mbstr...
# symfony/polyfill-php80 v1.25.0 v1.28.0 Symfony polyfill backporting s...
composer update
composer outdated
# Direct dependencies required in composer.json:
# Everything up to date
# Transitive dependencies not required in composer.json:
# Everything up to date
Last update: 317 days ago