Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert Hijri date to gregorian in PHP?

Tags:

date

php

I would like convert this date:09/13/1436 (it is Hijiri) to 2015-06-30(it is Gregorian). I tried that:

function HijriToJD($m, $d, $y){
   return (int)((11 * $y + 3) / 30) + 354 * $y + 
     30 * $m - (int)(($m - 1) / 2) + $d + 1948440 - 385;
}


$date = HijriToJD(09, 13, 1436);

echo jdtogregorian($date);

and when i made compile i got 10/7/2014. Someone have any idea??

like image 558
Khurian Avatar asked Jul 01 '15 09:07

Khurian


People also ask

How to get Hijri date in PHP?

$date = \GeniusTS\HijriDate\Hijri::convertToGregorian(8, 8, 1438); get date formated string.

How do I change the date format from Hijri to Gregorian in Excel?

On the Format menu, click Cells, and then click the Number tab. Select Custom from the list of categories.


1 Answers

Passing 09 as the month is the problem.... a number with a leading zero is treated as octal in PHP. 09 is invalid octal, so it is treated as a 0.

Calling

$r=HijriToJD(9, 13, 1436);

(without the leading zero for the month) should give you a correct result

like image 180
Mark Baker Avatar answered Sep 21 '22 15:09

Mark Baker