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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vickyhanif
Forum Newbie
Posts: 1
Joined: Sat Dec 12, 2015 11:38 am

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

Post 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; 
?>
Attachments
phpcode.JPG
phpcode.JPG (16.33 KiB) Viewed 1350 times
Last edited by Celauran on Sat Dec 12, 2015 12:54 pm, edited 1 time in total.
Reason: Please wrap your code in syntax tags
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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?
Post Reply