Moment

Sometimes you need to manage date. That's why we developed Moment. Moment allows you to manage dates simply.

Basic Usage

First you need to initialize Moment using the moment function:

$today = moment('today');
$yesterday = moment('yesterday');
$tomorrow = moment('tomorrow');

Here:

  • $today equals to today timestamps

  • $yesterday equals to yesterday timestamps

  • $tomorrow equals to tomorrow timestamps

If you don't pass a day as argument to the moment function, the today timestamps will be returned.

Adding date

Since you have initialized a moment, you can add value to this moment using the add function. Here is an example:

$today = moment('today');
$tomorrow = $today->add('1 day');
$next_month = $today->add('1 month');
$next_year = $today->add('1 year');

Removing date

You can also remove value to the current date with the remove function:

$today = moment();
$yesterday = $today->remove('1 day');
$previous_month = $today->remove('1 month');
$previous_year = $today->remove('1 year');

Getting Timestamps Value

If you want to get the timestamps value of an moment, use the timestamp function:

$tomorrow = moment('tomorrow');
echo $tomorrow->timestamp();

Formatting

You can get a formatted date of an moment using the format function:

$today = moment();

$formatted = $today->format();

//or
$formatted = $today->format('Y-m-d H:i:s');

echo $formatted;

Dernière mise à jour

Cet article vous a-t-il été utile ?