Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kenan-Amran's avatar

Function Arabic Date

Hello How can use this function to convert date after insert database from( 2016-10-15 08:09:00 - TO - أكتوبر 16 2016)

public static function getArabicMonth($data) { $months = [ "Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر" ];

    $day = date("d", strtotime($data));
    $month = date("M", strtotime($data));
    $year = date("Y", strtotime($data));

    $month = $months[$month];

    return $day . ' ' . $month . ' ' . $year;
}
0 likes
6 replies
willvincent's avatar
Level 54

I think the correct way to do this would be to configure Carbon with the appropriate locale (ar_SA.UTF-8?). Then just specifying the desired date format should give you your expected results.

1 like
Kenan-Amran's avatar

Can you help me how to use this function Or Where do I put this (ar_SA.UTF-8?) To output the date in Arabic

willvincent's avatar

You have to have to proper locale package installed... http://carbon.nesbot.com/docs/#api-localization

on Linux

If you have trouble with translations, check locales installed in your system (local and production).

locale -a to list locales enabled.

sudo locale-gen fr_FR.UTF-8 to install a new locale.

sudo dpkg-reconfigure locales to publish all locale enabled.

And reboot your system.

Kenan-Amran's avatar

Where do I change my settings of the Arabic language to date appears in Arabic

Kenan-Amran's avatar

When we user carbon the output is (Wednesday 28 September 2016)

Please or to participate in this conversation.