Convert Jalali calendar to Gregorian by PHP in CodeIgniter

✔ Recommended Answer

It's generally better to stick to existing libs rather than writing your own one.Try, for example, jDateTime or Gregorian-Jalali-Date-Convertor.

P.S. I never tried to use them myself, but first one looks much more solid.


Answered By: borisano

Method #2

To convert Jalali calendar to Gregorian calendar in PHP, you can use the jDateTime library which provides convenient methods to convert between Jalali and Gregorian calendars. In CodeIgniter, you can include this library in your project and use it to perform the conversion.

Here are the steps to do so:

  1. Download the jDateTime library from and place it in your CodeIgniter project's application/libraries folder.

  2. Load the library in your CodeIgniter controller or model:

  1. Use the date method of the jDateTime class to convert a Jalali date to a Gregorian date:
// Convert "1399-01-01" (Jalali date) to a Gregorian date $gregorianDate = $this->jdatetime->date('Y-m-d', strtotime('1399-01-01'));

In this example, we use the date method to convert the Jalali date 1399-01-01 to a Gregorian date. The second argument of the strtotime function is used to convert the Jalali date to a Unix timestamp, which is then passed to the date method.

Note that the jDateTime library also provides other methods to format dates, parse dates, and perform other operations with Jalali and Gregorian calendars. You can consult the library's documentation for more information.


Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned

Laravel file upload returns forbidden 403, file permission is 700 not 755