This RFC proposes adding a new function intl_date_format() to the intl extension that provides a simple, unified interface for formatting dates across different calendar systems (Gregorian, Persian, Islamic, etc.) using ICU's calendar capabilities.
Currently, PHP developers must manually instantiate IntlDateFormatter and configure calendar types through locale strings or setter methods. This RFC introduces a procedural function that simplifies calendar-aware date formatting for common use cases.
Add a new function to the intl extension:
function intl_date_format( string|int $date, string $calendar = 'gregorian', string $locale = 'en_US', string $pattern = 'yyyy/MM/dd' ): string|false
$date (string|int, required)time(), strtotime())2026-09-27 or 2026-09-27T14:30:00Z)$calendar (string, optional, default: gregorian)gregorian, persian, islamic, islamic-civil, japanese, buddhist, chinese, indian, coptic, ethiopic, hebrew@calendar=<value> to the locale string$locale (string, optional, default: en_US)fa_IR, ar_SA, en_US, de_DE)@calendar= suffix (handled automatically by the function)en_US with a warning$pattern (string, optional, default: yyyy/MM/dd)yyyy: 4-digit year, yy: 2-digit yearMM: 2-digit month, MMM: short month name, MMMM: full month namedd: 2-digit day, d: day without leading zeroEEEE: full weekday name, EEE: short weekday nameHH: 24-hour, hh: 12-hour, mm: minutes, ss: secondsa: AM/PM markerfalse and emits a warning when:
The function follows PHP's standard error handling conventions for intl functions:
$date: Returns false and emits E_WARNING$calendar: Returns false and emits E_WARNING$locale: Emits E_WARNING and falls back to en_US$pattern: Returns false and emits E_WARNINGfalse and emits E_WARNINGintl_get_error_message()Example error handling:
<?php $result = intl_date_format('invalid-date', 'persian', 'fa_IR'); if ($result === false) { echo "Error: " . intl_get_error_message() . "\n"; echo "Error code: " . intl_get_error_code() . "\n"; } ?>
<?php // Format current timestamp in Persian calendar echo intl_date_format(time(), 'persian', 'fa_IR'); // Output: 1405/07/05 echo intl_date_format(time(), 'persian', 'fa_IR', 'd MMMM yyyy'); // Output: ۵ مهر ۱۴۰۵ ?>
<?php // Format specific date in Islamic calendar $date = '2026-09-27'; echo intl_date_format($date, 'islamic', 'ar_SA', 'd MMMM yyyy'); // Output: ٢٤ ربيع الأول ١٤٤٨ echo intl_date_format($date, 'islamic-civil', 'en_US'); // Output: 1448/03/24 ?>
<?php $timestamp = strtotime('2026-09-27'); // English echo intl_date_format($timestamp, 'gregorian', 'en_US', 'EEEE, MMMM d, yyyy'); // Output: Sunday, September 27, 2026 // German echo intl_date_format($timestamp, 'gregorian', 'de_DE', 'EEEE, d. MMMM yyyy'); // Output: Sonntag, 27. September 2026 ?>
<?php // Using ISO 8601 date string instead of timestamp $isoDate = '2026-09-27T14:30:00Z'; echo intl_date_format($isoDate, 'persian', 'fa_IR', 'yyyy/MM/dd HH:mm'); // Output: 1405/07/05 14:30 echo intl_date_format($isoDate, 'gregorian', 'en_US', 'MMM d, yyyy h:mm a'); // Output: Sep 27, 2026 2:30 PM ?>
None. This is a new function.
PHP 8.7
None.
This adds a new function to the existing intl extension. No changes to existing intl functions..
None.
None at this time.
IntlDateFormatter class remains unchangeddate(), strftime(), etc.) are unaffectedDateTime or DateTimeImmutable classesDateTimeInterface for calendar conversionintl_date_parse() function for reverse operation
Accept intl_date_format() as proposed? Yes/No (requires 2/3 majority).
Voting opens: TBD Voting closes: TBD (minimum 2