Change language

PHP DateTimeImmutable add () function

Syntax:
DateTimeImmutable DateTimeImmutable::add (DateInterval $interval)
Parameters:This function takes one parameter, $interval,which contains the number of days, months, years, hours, minutes, or seconds to be added to this DateTimeImmutable object. Return Values:This function returns the final DateTimeImmutable object after adding.The following programs illustrate the DateTimeImmutable::add() function in PHP:Program 1:This program uses the DateTimeImmutable::add() function to add 2 days to the DateTimeImmutable object.
// PHP illustration program DateTimeImmutable::add()
// function  
// Create a new DateTimeImmutable::add() $datetime = new DateTimeImmutable ( "2019-10-03T10: 00: 00" );  
// Initialize a date interval of 2 days $interval = ’P2D’ ;  
// Call the add() function $datetime = $datetime -> add ( new DateInterval ( $interval ));  
// Get the new date in
// format ’ Ymd H: i: s ’ echo $datetime -> format ( ’Ymd H: i: s’ ); ?>
Exit:
2019-10 -05 10:00:00
Program 2:This program uses the DateTimeImmutable::add() function to add DateInterval ’ P2Y5M2DT0H30M40S ’ to the DateTimeImmutable object.
// PHP illustration program DateTimeImmutable::add()
// function 
// Create a new DateTimeImmutable::add() $datetime = new DateTimeImmutable ( "2019-10-03T10 : 00: 00 " );  
// Initialize the DateInterval object $interval = ’P2Y5M2DT0H30M40S’ ;  
// Call the add() function $datetime = $datetime -> add ( new DateInterval ( $interval ));  
// Get the new date in
// format ’ Ymd H: i: s ’ echo $datetime -> format ( ’Ymd H: i: s’ ); ?>
Exit:
2022-03 -05 10:30:40
Link: https: / /www.php.net/manual/en/datetimeimmutable.add.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method