Aleš Sýkora / March 1, 2022 / 0 comments

Date difference in current language

Post summary: This script takes the date string and echo the date in wanted format and difference between current date.

This script takes the date string and echo the date in wanted format and difference between current date.

<?php

$dateString = "2022-03-14 12:00";

$lang = 'cs_CZ';  // set your lang
$fmt = new IntlDateFormatter($lang, NULL, NULL);
$fmt->setPattern('d MMMM yyyy HH:mm');
$date = DateTime::createFromFormat('Y-m-d H:i', $dateString);
echo $fmt->format($date); 


$now = new DateTime();
$diff = $now->diff($date);

echo "<br>";

echo "The difference is $diff->d days, $diff->h hours, $diff->i minutes";

Fuel my passion for writing with a beer🍺

Your support not only makes me drunk but also greatly motivates me to continue creating content that helps. Cheers to more discoveries and shared success. 🍻

0 comments

Share Your Thoughts