note 98127 deleted from class.datetime by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: Vanylla.com 

----

The add methos is confusing and too long to be used cause you have to create a DateInterval object. We extended the DateTime class by adding methods that are frequently used in our applications' code:

<?php
addDays($number_of_days)
addMonths($number_of_months)
//etc.
?>

don't know if PHP will ever add those, in the meantime you could do:

<?php
class MyDateTime extends DateTime
{
   public function addDays($number_of_days)
   {
      //below use 'D' for days, 'Y' for years, 'M' for months,
      $this->add(new DateInterval('P' . $number_of_days . 'D'));
   }

   //public function addMonths...
   //public function addYears...
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.