roozbeh360 / Gregorian-Jalali-Date-Convertor

Gregorian-Jalali Date Convertor php script
19 stars 10 forks source link

Jalali to Gregorian #1

Closed arifshariati closed 9 years ago

arifshariati commented 9 years ago

The function jalali_to_gregorian does not produce exact Gregorian date for Jalali date. Suppose Today's date is 29-08-1393 and equivalent date in Gregorian is 20 Nov 2014 however the function outputs 2591/3/21

roozbeh360 commented 9 years ago

it's work perfectly ! can you copy your code here and show me how you use this ? remember you must separate year and month and day to use it on this function .

print_r(      jalali_to_gregorian(1393, 8, 26,false)
             );

print_r(      jalali_to_gregorian(1393, 8, 26,true)
             );
arifshariati commented 9 years ago

Here is my code in Codeigniter

$year=date('Y',strtotime($this->input->post('sem_end_date'))); $month=date('m',strtotime($this->input->post('sem_end_date'))); $day=date('d',strtotime($this->input->post('sem_end_date'))); $_POST['sem_end_date']=modules::run('dateconverter/jalali_to_gregorian',$year,$month,$day,TRUE);

roozbeh360 commented 9 years ago

first debug your code using ide to see if , for exp $year has same value as $this->input->post('sem_end_date') .don't forget type casting (int) some times different type of values like string can not be calculated depending on server php lib

$year=date('Y',strtotime($this->input->post('sem_end_date')));
$month=date('m',strtotime($this->input->post('sem_end_date')));
$day=date('d',strtotime($this->input->post('sem_end_date')));
$_POST['sem_end_date']=modules::run('dateconverter/jalali_to_gregorian',$year,$month,$day,TRUE);

ok use this maybe it's help you find out .

$year=(int)date('Y',strtotime($this->input->post('sem_end_date')));
$month=(int)date('m',strtotime($this->input->post('sem_end_date')));
$day=(int)date('d',strtotime($this->input->post('sem_end_date')));
$_POST['sem_end_date']=modules::run('dateconverter/jalali_to_gregorian',$year,$month,$day,TRUE);
arifshariati commented 9 years ago

it is not working