morilog / jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in php appliations, based on Jalali (Shamsi) DateTime class.
MIT License
856 stars 111 forks source link

Gregorian to Jalali #112

Closed dlbaran closed 3 years ago

dlbaran commented 3 years ago

Hi, I need to display the date stored in the Gregorian database in Jalali. How can I do this using your library? My codes are as follows:

elseif($column_type_lookup[$column_name] == 'date'){ //date with format MM/DD/YYYY if(!empty($row[$column_name]) && ($row[$column_name] != '0000-00-00')){ $form_data[$i][$j] = date('M d, Y',strtotime($row[$column_name])); }

                if($column_name == 'date_created' || $column_name == 'date_updated'){
                    $form_data[$i][$j] = mf_short_relative_date($row[$column_name]);
                }
            }elseif($column_type_lookup[$column_name] == 'europe_date'){ //date with format DD/MM/YYYY

                if(!empty($row[$column_name]) && ($row[$column_name] != '0000-00-00')){
                    $form_data[$i][$j]  = date('d M Y',strtotime($row[$column_name]));
                }
            }
MmKargar commented 3 years ago

the easiest syntax is:

jdate($databaseDate)->format('Y-m-d H:i:s');
dlbaran commented 3 years ago

the easiest syntax is:

jdate($databaseDate)->format('Y-m-d H:i:s');

Dear Kargar, Thank you for your help. Excuse me, I am a beginner in php. Can you give me some tips on how I can use this code? Best Regards,

MmKargar commented 3 years ago

not much to do. if you are using laravel , you can use this syntax anywhere(controller , model, view , etc..) :

return jdate('2020-12-07')->format('Y-m-d'); // output : 1399-09-17

and if you are using just php without framwork :

require "/vendor/autoload.php";
echo jdate('2020-12-07')->format('Y-m-d'); // output : 1399-09-17

and if you want more examples , just check the Morilog/jalali Readme