1. Go to this page and download the library: Download nabeghe/dati 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/ */
nabeghe / dati example snippets
use Nabeghe\Dati\Dati;
# Convert Gregorian to Jalali
echo "1995-11-20 00:00:00 To Jalali = ".Dati::toJalali('1995-11-20 00:00:00')."\n"; // 1374-08-29 00:00:00
# Convert Jalali to Gregorian
echo "1374-08-29 00:00:00 To Jalali = ".Dati::fromJalali('1374-08-29 00:00:00')."\n"; // 1995-11-20 00:00:00
# Detect Format:
echo '1995-11-20 00:00:00 Format = '.Dati::detectFormat('1995-11-20 00:00:00')."\n"; // Y-m-d H:i:s
# Difference between two datetimes:
echo 'Diff between 1995-11-20 00:00:00 & 1995-11-20 00:00:01 = '.Dati::diff('1995-11-20 00:00:00', '1995-11-20 00:00:01')."\n"; // 1 seconds
echo 'Diff between 1995-11-20 00:00:00 & 1995-11-31 00:00:00 = '.Dati::diff('1995-11-20 00:00:00', '1995-11-31 00:00:00', 'days')."\n"; // 11 days
echo 'Diff between 1995-11-20 00:00:00 & 1995-11-31 12:00:00 = '.Dati::diff('1995-11-20 00:00:00', '1995-11-31 12:00:00', 'days')."\n"; // 11.5 days
echo 'Diff between 1995-11-20 00:00:00 & 2024-10-19 22:58:00 = '.((int) Dati::diff('1995-11-20 00:00:00', '2024-10-19 22:58:00', 'years'))."\n"; // 28 years
# Difference between two dates based on largest possible unit:
echo "How Long Ago From 2024-10-19 00:00:00 to 2025-10-19 00:00:00 = ".json_encode(Dati::howLongAgo('2024-10-19 00:00:00', '2025-10-19 00:00:00'))."\n";
// Output: {"unit":"years","value":1,"diff":31536000}
# Check leap Year
echo 'Year 2024 gregorian '.Dati::isLeap(2024) ? "is leap\n" : "is not leap\n";
echo 'Year 1403 Jalali '.Dati::isLeap(1403, true) ? "is leap\n" : "is not leap\n";
# Join a value to datetime:
echo 'Join 1 secoonds to 1995-11-20 00:00:00 = '.Dati::join('+1', 'seconds', '1995-11-20 00:00:00')."\n"; // 1995-11-20 00:00:0
echo 'Join 2 weeks to 1995-11-20 00:00:00 = '.Dati::join('+2', 'weeks', '1995-11-20 00:00:00')."\n"; // 1995-12-04 00:00:00
echo 'Join 3 months to 1995-11-20 00:00:00 = '.Dati::join('3', 'month', '1995-11-20 00:00:00')."\n"; // 1996-02-20 00:00:00
# Remaining value until expiration! Suitable for things like premium subscriptions that have validity:
echo 'Remaining minutes to reach 2024-10-20 00:00:00 since 2024-10-19 23:00:00 = '.Dati::remaining('2024-10-19 23:00:00', '2024-10-20 00:00:00', 60, 'minutes')."\n"; // 0
echo 'Remaining minutes to reach 2024-10-20 00:00:00 since 2024-10-19 23:00:00 '.((int) Dati::remaining('2024-10-19 23:00:00', '2024-10-20 00:00:00', 120, 'minutes'))."\n"; // 60
echo 'Parsed Unit `1s` = '.json_encode(Dati::parseUnit('1s'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1S` = '.json_encode(Dati::parseUnit('1S'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1sec` = '.json_encode(Dati::parseUnit('1sec'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1Sec` = '.json_encode(Dati::parseUnit('1Sec'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1second` = '.json_encode(Dati::parseUnit('1second'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1Second` = '.json_encode(Dati::parseUnit('1Second'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1seconds` = '.json_encode(Dati::parseUnit('1seconds'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1Seconds` = '.json_encode(Dati::parseUnit('1Seconds'))."\n"; // [1,"seconds"]
echo 'Parsed Unit `1 s` = '.json_encode(Dati::parseUnit('1 s'))."\n"; // [1,"seconds"]
echo 'Parsed Unit ` 1 s ` = '.json_encode(Dati::parseUnit('1 s '))."\n"; // [1,"seconds"]
echo 'Parsed Unit `2m` = '.json_encode(Dati::parseUnit('2m'))."\n"; // [2,"minutes"]
echo 'Parsed Unit `3h` = '.json_encode(Dati::parseUnit('3h'))."\n"; // [3,"hours"]
echo 'Parsed Unit `4d` = '.json_encode(Dati::parseUnit('4d'))."\n"; // [4,"days"]
echo 'Parsed Unit `5w` = '.json_encode(Dati::parseUnit('5w'))."\n"; // [5,"weeks"]
echo 'Parsed Unit `6M` = '.json_encode(Dati::parseUnit('6M'))."\n"; // [6,"months"]
echo 'Parsed Unit `7y` = '.json_encode(Dati::parseUnit('7y'))."\n"; // [7,"years"]
// Syntax:
Diff::checkSpam(array $datetimes, int $offset = 1, int $limit = 3, $strict = false)
use Nabeghe\Dati\Now;
echo "Now (GMT): " . Now::datetime() . "\n";
echo "Now (GMT): " . Now::datetime() . "\n"; // The output will be the same as before. The time has been cached.
echo "Now (Local): " . Now::datetimeNew() . "\n";
echo "Now (Local): " . Now::datetimeLocal() . "\n";
echo "Now (Local): " . Now::datetimeLocal() . "\n"; // The output will be the same as before. The time has been cached.
echo "Now (Local): " . Now::datetimeLocalNew() . "\n";