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
ID: 21787344
instead of explode & mktime consider using strtotime

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


Author Comment

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

Expert Comment

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.

Author Closing Comment

ID: 31467290
Thanks for your help.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Php Email function not working with Template 8 38
Echo images using file system 2 29
PHP Undefined Index in HTML Form? 2 31
xampp tool 12 23
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
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.

932 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

12 Experts available now in Live!

Get 1:1 Help Now