DateTimeImmutable

We can use DateTimeImmutable in place of DateTime class when we want the original object is not to be modified.

Using date add ...
$date1=new DateTime('2018-04-23'); // date object created. 
$date1->add(new DateInterval('P1Y3M')); // inerval of 1 year 3 months added
echo $date1->format('Y-M-d'); // Output is 2019-Jul-23
/// by using DateTimeImmutable ///
$date1=new DateTimeImmutable('2018-04-23'); // date object created . 
$date1->add(new DateInterval('P1Y3M')); // inerval of 1 year 3 months added
echo $date1->format('Y-M-d'); //  Output is 2018-Apr-23
In case of date object created using DateTimeImmutable after adding the interval the original value never changes.


plus2net.com






Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer