PHP class - need help with dates formats

Posted on 2008-06-14
Last Modified: 2010-04-21
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.


//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');


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

Question by:sabecs
  • 2
  • 2
LVL 19

Accepted Solution

bevhost earned 500 total points
Comment Utility
instead of explode & mktime consider using strtotime

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


Author Comment

Comment Utility
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?
LVL 19

Expert Comment

Comment Utility
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.

Author Closing Comment

Comment Utility
Thanks for your help.

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
update field on focusout 15 19
php variable basic question 12 27
wordpress issue 2 15
Why does my array not "dump?" 5 4
Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now