Change language

PHP DateTime sub () function

Syntax:
  • Object Oriented Style:
    DateTime DateTime::sub (DateInterval  interval)
  • Procedural style:
    DateTime date_sub (DateTime $object, DateInterval $interval)
Parameters:This function uses two parameters as above and described below:
  • $object:this parameter contains a DateTime object created by the date_create() function.
  • $interval:this parameter contains a DateInterval object.
Return Values:This function returns a DateTime object after subtraction on success or False on failure.The following programs illustrate the DateTime::sub function() in PHP:Program 1:This program uses the DateTime::sub() function to subtract 2 days from a given date object.

 
// PHP illustration program DateTime::sub()
// function 
/ / Create a new DateTime() object $datetime = new DateTime ( ’ 2019-10-03’ ) ;  
// Initialize interval 2 days $interval = ’P2D’ ;  
// Call the sub() function $datetime -> sub ( new DateInterval ( $interval ));  
// Get a new date
// format ’ Ymd ’ echo $datetime -> format ( ’Ymd’ ); ?>
Exit:
2019-10 -01
Program 2:This program uses the DateTime::sub() function to subtract a specified interval from a date object.
// PHP illustration program DateTime::sub()
// function 
// Create a new DateTime object ( ) $datetime = new DateTime ( ’2019-10-03’ );  
// Initialize spacing $interval = ’P2Y5M2DT0H30M40S’ ;  
// Call the sub() function $datetime -> sub ( new DateInterval ( $interval ));  
// Get a new date
// format ’ Ymd H: i: s ’ echo $datetime -> format ( ’Ymd H: i: s’ );  
?>
Exit:
2017-04 -30 23:29:20
Link: https: / /www.php.net/manual/en/datetime.sub.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