Php Code help .... (months & date)

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:

      <?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; 
?>

The output is:

    $monthDescription.= ' from ('.sdate($fromdate). ' till '.sdate($todate).')';

In the script supplied, the format or calculation is not shown for $fromdate.

If and only if $fromdate is in a “timestamp” format then formatting options are avaialable here:

Php Format date()

**Example: **

  $fromdate = time();

    echo date('l, F jS, Y H:i:s', $fromdate);

    // output: **Sunday, December 13th, 2015 02:53:32**

Edit:
Anouther useful PHP function is Strtotime

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.