Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP class - need help with dates formats

Posted on 2008-06-14
4
Medium Priority
?
210 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
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
bevhost earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

972 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