How to convert Hijri date to gregorian in PHP?

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

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 did the compilation, I got 10/7/2014. Does anyone have an idea?

+7
date php
source share
1 answer

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

Call

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

(no leading zero per month) should give you the correct result

+6
source share

All Articles