PHP date_sub() Function
In this chapter you will learn:
- Definition for PHP date_sub() Function
- Syntax for PHP date_sub() Function
- Parameter for PHP date_sub() Function
- Return value from PHP date_sub() Function
- Example
Definition
The date_sub() function subtracts some days, months, years, hours, minutes, and seconds from a date.
Syntax
PHP date_sub() Function has the following syntax.
date_sub(object,interval);
Parameter
Parameter | Is required | Description |
---|---|---|
object | Required. | DateTime object returned by date_create() |
interval | Required. | DateInterval object |
Return
PHP date_sub() Function returns a DateTime object on success. FALSE on failure.
Example
Subtract 40 days from the 15th of March, 2013:
<?php/*from j a v a 2s .c o m*/
$date=date_create("2013-03-15");
date_sub($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP date_sun_info() Function
- Syntax for PHP date_sun_info() Function
- Parameter for PHP date_sun_info() Function
- Return for PHP date_sun_info() Function
- Example
Home » PHP Tutorial » PHP Date Functions