Table of Contents

PHP RFC: intl_date_format()

Introduction

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.

Proposal

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

Parameters

Return Value

Error Handling

The function follows PHP's standard error handling conventions for intl functions:

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";
}
?>

Examples

Example 1: Persian (Jalali) Calendar

<?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: ۵ مهر ۱۴۰۵
?>

Example 2: Islamic (Hijri) Calendar

<?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
?>

Example 3: Gregorian Calendar with Multiple Locales

<?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
?>

Example 4: ISO 8601 String Input

<?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
?>

Backward Incompatible Changes

None. This is a new function.

Proposed PHP Version(s)

PHP 8.7

RFC Impact

To SAPIs

None.

To Existing Extensions

This adds a new function to the existing intl extension. No changes to existing intl functions..

Unaffcache

None.

Open Issues

None at this time.

Unaffected PHP Functionality

Future Scope

Proposed Voting Choices

Accept intl_date_format() as proposed? Yes/No (requires 2/3 majority).

Voting opens: TBD Voting closes: TBD (minimum 2