Solved

PHP class - need help with dates formats

Posted on 2008-06-14
4
205 Views
Last Modified: 2010-04-21
Hi,
I am trying to write my first PHP class and I am not sure I know exactly what I doing.
Basically I want to be create new orders or update and existing order and return dates in both MySQL format and in a format for viewing, most orders will be new but some might be updates that already have a current expiry date.
Any assistance or comments would be appreciated.

<?php 
 
 
//new placeOrder($current_expdate, $days, $special, $credit, $amount, $payment_option, $payment_type);
 
class placeOrder{
   
   function placeOrder($expiry_date, $days='90', $special='1', $credit='1',$amount='99.00', $payment_option='None', $payment_type='Credit'){ 
				
 
 
				if (isset($expiry_date)) {
				
				//Get current expiry date and add days to current date
				$this->mysql_expiry_date = $expiry_date; 
				$expiry_date = explode("-", $expiry_date);
				$expiry_date = mktime (0,0,0,date($expiry_date[1]) ,date($expiry_date[2]) ,date($expiry_date[0]));
				$new_expiry_date = ($expiry_date + ((24 * 60 * 60 * $days) * $special));
				$this->display_new_expiry_date = date("D jS M, Y", $new_expiry_date);
				$new_expiry_date = date("Y-m-d", $new_expiry_date);
				
				}else { 
		        $new_expiry_date = date("Y-m-d", time());
				}
				
				$this->new_expiry_date = $new_expiry_date;
				
				
				
				$this->display_expiry_date = date("D jS M, Y", $new_expiry_date);
				$this->mysql_current_date = date("Y-m-d",$current_expiry_date);  
				$this->display_current_date = date("F jS, Y",$current_expiry_date);;
			
				$this->display_order_date = date("D jS M, Y",time() + ((24 * 60 * 60 )));
 
				$this->mysql_order_date = date("Y-m-d",time() + ((24 * 60 * 60 )));
				$this->adlength = ($days * $special * $credit);
				$this->amount = $amount;
				$this->payment_option = $payment_option; 
	 			$this->payment_type = $payment_type; 
			 } 
 
	
	
				function new_order_report(){
					echo "<br>New Order Details<br>"; 
					echo "Payment Type: $this->payment_type <br>"; 
					echo "Advertisment Amount Paying : $this->amount <br>";
					echo "Payment Option: $this->payment_option<br>";
					
					echo "<br>Ad Length: $this->adlength Days"; 
					echo "<br>List Date: $this->display_order_date"; 
					echo "<br>Expiry Date: $this->display_expiry_date";
					
					
					echo "<br>Order Date: $this->display_order_date";
					echo "<br>List Date: $this->mysql_order_date";
					echo "<br>Expiry Date: $this->mysql_expiry_date<br>";
			
				}	
			
			function updated_order_report(){
					echo "<br>Updated Order Details<br>"; 
					echo "Payment Type: $this->payment_type <br>"; 
					echo "Advertisment Amount Paying : $ $this->amount <br>";
					echo "Payment Option: $this->payment_option<br>";
					
					echo "<br>Ad Length: $this->adlength Days"; 
					echo "<br>List Date: $this->display_order_date"; 
					
					echo "<br>Order Date: $this->display_order_date";
					echo "<br>New Expiry Date - MySQL format: $this->new_expiry_date";
					echo "<br>New Expiry Date - Screen format: $this->display_new_expiry_date";
					echo "<br>Old Expiry Date - MySQL Format: $this->mysql_expiry_date<br>";
			
				}	
 
}
 
//new placeOrder($current_expdate, $days, $special, $credit, $amount, $payment_option, $payment_type);
$update_order = new placeOrder('2009-01-01',35,1,1,'30.00','Credit Card','Paid');
$update_order->updated_order_report();
 
new placeOrder($current_expdate, $days, $special, $credit, $amount, $payment_option, $payment_type);
$private_order = new placeOrder('',90,1,1,'30.00','Cheque','Paid');
$private_order ->new_order_report();
 
?>

Open in new window

0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
bevhost earned 500 total points
ID: 21787344
instead of explode & mktime consider using strtotime

                                $expiry_date=strtotime($expiry_date);
                                $new_expiry_date=strtotime($days." days",$expiry_date);

0
 

Author Comment

by:sabecs
ID: 21788139
Thanks bevhost for your help, just wondering if there is a better way to code the whole thing or is the way a class should be created?
0
 
LVL 19

Expert Comment

by:bevhost
ID: 21799126
Clases are great if you have several different kind's of orders.
This way you can create a base class that has all the most common functions,
but when you need a custom order you can extend the class and redeclare or add any functions that need to be different.
0
 

Author Closing Comment

by:sabecs
ID: 31467290
Thanks for your help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question