Page 1 of 1

Php code help .... (date, months)

Posted: Sat Dec 12, 2015 11:42 am
by vickyhanif
Hi Everyone ... I need a small help about below code and output. Currently output of the code is showing rent from specific dates which is chosen by client (from October 21, 2015 till January 21, 2015).

In the output you can see it is showing October 2015, November 2015 & December 2015 from (21/10/2015 till 21/01/2016). But I want to show it in this way October 2015, November 2015, December 2015 & January 2016 from (October 21, 2015 till January 21, 2016)

Can someone help me to fix this code accordingly. thanks

OUTPUT:
"Canon IRC 4080i Advance Rent for the month(s) of October 2015, November 2015 & December 2015 from (21/10/2015 till 21/01/2016)"

CODE:

Code: Select all

      <?php 
		$monthDescription = "";
		//$monthDescription = $rs1['totalmonth'] . " Months";
		if($rs1['totalmonth']==3)
		{
			//$monthDescription = "Quartely";
		}
		else if($rs1['totalmonth']==6)
		{
			//$monthDescription = "Half Yearly";
		}
		else if($rs1['totalmonth']==12)
		{
			//$monthDescription = "Yearly";
		}
		$monthDescription.=' Rent for the month(s) of <br /> ';
		
		$monthNumber=1;
		if(!is_null($fromdate)){
			$monthNumber=sgetmonth($fromdate);
			$year=sdbyear($fromdate);
		}
		for($i=1;$i<=$rs1['totalmonth'];$i++)
		{
			if($monthNumber==13)
			{
				$monthNumber=1;
				$year = $year + 1;
			}
			$monthName = snummonth($monthNumber);
			if($rs1['totalmonth']==1 || $rs1['totalmonth']==$i)
			{
				$monthDescription.= $monthName . ' ' . $year. ' ';				
			}
			else if($rs1['totalmonth']==($i+1))
			{
				$monthDescription.= $monthName . ' ' . $year. ' & ';
			}
			else
			{
				$monthDescription.= $monthName . ' ' . $year. ', ';
			}
			$monthNumber++;
		}
		if($rs1['totalmonth']>1)
		{
			$fromMonthName="";
			$fromYear="";
			$fromDay="";
			$toMonthName="";
			$toYear="";
			$toDay="";
			if(!is_null($fromdate)){
				$fromMonthName=sdbmonth($fromdate);
				$fromYear=sdbyear($fromdate);
				$fromDay=sgetday($fromdate);
			}		
			if(!is_null($todate)){
				$toMonthName=sdbmonth($todate);
				$toYear=sdbyear($todate);
				$toDay=sgetday($todate);
			}		
			$monthDescription.= ' from ('.sdate($fromdate). ' till '.sdate($todate).')';
		}
	?>
      <?php echo ''.$rs1['modelnumber'] . ' Advance '.$monthDescription; 
?>

Re: Php code help .... (date, months)

Posted: Sat Dec 12, 2015 9:50 pm
by requinix

Code: Select all

$monthDescription.= ' from ('.sdate($fromdate). ' till '.sdate($todate).')';
The code is using the "sdate" function to format the two dates. What is the code for that? Could it be using some kind of global formatting preference for dates?