Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert gregorian date to islamic date in php and store it in database?

Tags:

php

I want to get synchronized Hijri and Gregorian and store both in database in php. How can it be done?

like image 909
Ashna Ali Avatar asked Oct 16 '25 22:10

Ashna Ali


1 Answers

Use HijriDateLib to convert Hijri dates to Gregorian, store dates is database as unix timestamp (data type bigint).

First you must download and require the Hijri class

<?php
require_once('hirji.class.php');

To return current date with both Hijri and Gregorian use:

echo (new hijri\datetime())->format('D _j _M _Yهـ (j-m-Yم)');

to store Hijri date in database:

SQL="INSERT IN table1 (timestamp_colum) VALUES " . (hijri\datetime::createFromHijri(1441,9,17))->format('U');

to view stored date with both Hijri and Gregorian:

echo (new hijri\datetime($row->timestamp_column))->format('D _j _M _Yهـ (j-m-Yم)');
like image 81
hubaishan Avatar answered Oct 19 '25 13:10

hubaishan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!