11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 12 • DATE AND TIMEwww.it-ebooks.infoCalculating the Difference between Two DatesIt's often useful to calculate the difference between two dates, for instance in order to provide the userwith an intuitive way to gauge pending deadlines. Consider an application where users pay asubscription fee to access online training material. A user's subscription is about to end, so you'd like toe-mail him a reminder stating something to the effect of, "Your subscription ends in 5 days! Renewnow!"To create such a message you'll need to calculate the number of days between today and thesubscription termination date. You can use the diff() method to perform the task:$terminationDate = new DateTime('2010-05-30');$todaysDate = new DateTime('today');$span = $terminationDate->diff($todaysDate);echo "Your subscription ends in {$span->format('%d')} days!";The classes and methods described in this section cover only part of the new date and time featuresmade available with the <strong>PHP</strong> 5.1 release, except for the use of the diff() method in the previousexample, which requires <strong>PHP</strong> 5.3.0 or newer. Be sure to consult the <strong>PHP</strong> documentation for a completesummary.SummaryThis chapter covered quite a bit of material, beginning with an overview of several date and timefunctions that appear almost daily in typical <strong>PHP</strong> programming tasks. Next up was a journey into theancient art of Date Fu, where you learned how to combine the capabilities of these functions to carry outuseful chronological tasks. I concluded the chapter with an introduction to <strong>PHP</strong> 5.1’s object-orienteddate-manipulation features.The next chapter focuses on the topic that is likely responsible for piquing your interest in learningmore about <strong>PHP</strong>: user interactivity. I’ll jump into data processing via forms, demonstrating both basicfeatures and advanced topics such as how to work with multivalued form components and automatedform generation.286

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!