Change language

PHP DateTimeImmutable :: sub () Function

Syntax:
DateTimeImmutable::sub (interval)
Parameters:this the function takes a intervalof parameters, which is the number of days, months, years, hours, minutes, or seconds to subtract from the given DateTimeImmutable object.Returned values ​​::this function returns the final date and time after subtraction.The programs below illustrate the DateTimeImmutable::sub() function:Program 1 : this the program reduces the number of days by 2.
// PHP program for illustration DateTimeImmutable::sub()
// function 
// Create a new DateTi object meImmutable() $datetimeImmutable = new DateTimeImmutable ( ’2019-10-07’ );  
// Initialize interval 2 days $interval = ’P2D’ ;  
// Calling the DateTimeImmutable::sub() function $a = $datetimeImmutable -> sub ( new DateInterval ( $interval ));  
// Get a new date
// format ’ Ymd ’ echo $a -> format ( ’Ymd’ ); ?>
Output:
2019-10-05 
Program 2 : This program reduces the month by 5.
// PHP illustration program DateTimeImmutable::sub()
// function 
// Create a new DateTimeImmutable() $datetimeImmutable = new DateTimeImmutable ( ’2019-10-07’ );  
// Initialize interval 5 months $interval = ’P5M’ ;  
// Calling the DateTimeImmutable::sub() function $a = $datetimeImmutable -> sub ( new DateInterval ( $interval ));  
// Get a new date
// format ’ Ymd ’ echo $a -> format ( ’Ymd’ ); ?>
Output:
2019-05-07 
Link
https://devdocs.io/php/datetimeimmutable.sub

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