I want to get synchronized Hijri and Gregorian and store both in database in php. How can it be done?
Asked
Active
Viewed 4,333 times
4
-
She wants to do it with php only, not with Javascript @RiggsFolly – Asfandyar Khan Feb 20 '17 at 12:15
-
I would suggest it would be simpler to maintain if you standardize on one calendar and then write/find a converter – RiggsFolly Feb 20 '17 at 12:21
-
Ok what if I have gregorian calendars dates. How can I convert them into Hijri dates? – Ashna Ali Feb 20 '17 at 12:35
-
Look for a class converting Gregorian to Hijiri dates. For example this one: https://www.phpclasses.org/package/6848-PHP-Convert-dates-between-Gregorian-to-Hijri-calendars.html#information – David162795 Feb 20 '17 at 12:48
1 Answers
3
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م)');

hubaishan
- 51
- 1
- 1
- 6