11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 12 • DATE AND TIMEThere are 28 days in February 2010.Calculating the Date X Days from the Present DateIt’s often useful to determine the precise date of some specific number of days into the future or past.Using the strtotime() function and GNU date syntax, such requests are trivial. Suppose you want toknow what the date will be 45 days into the future, based on today’s date of May 24, 2010:$futuredate = strtotime("+45 days");echo date("F d, Y", $futuredate);This returns the following:July 08, 2010By prepending a negative sign, you can determine the date 45 days into the past (today being May24, 2010):$pastdate = strtotime("-45 days");echo date("F d, Y", $pastdate);This returns the following:April 09, 2010What about ten weeks and two days from today (May 24, 2010)?$futuredate = strtotime("10 weeks 2 days");echo date("F d, Y", $futuredate);This returns the following:August 04, 2010Date and Time Enhancements for <strong>PHP</strong> 5.1+ UsersEnhanced date- and time-related capabilities were added with the <strong>PHP</strong> 5.1 release. Not only was aconvenient object-oriented interface added, but so was the ability to manage your dates and times inrespect to various time zones. Although this DateTime class also offers a functional interface, thissection will focus upon the highlights of its object-oriented interface.283

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

Saved successfully!

Ooh no, something went wrong!