(PHP 5 >= 5.3.0)

date_subAlias de DateTime::sub()


Esta funciĆ³n es un alias de: DateTime::sub()

add a note add a note

User Contributed Notes 3 notes

vitkor dot kruglikov at gmail dot com
1 month ago
It can be unclear for someone how to use this function.
Here is the example:

date_sub($date,date_interval_create_from_date_string("40 days"));
echo date_format($date,"Y-m-d");
Thomas LEDUC
5 months ago
To glue to the OOP, it's better to use it with DateInterval::createFromDateString

= new DateTime('2020-12-20');
$dateA = $dateB->sub(DateInterval::createFromDateString('10 days'));

more detail here :
public static function createFromDateString ($time) {}
Jonathan Poissant
4 years ago
You cannot replace date_sub('2000-01-20') by DateTime::sub('2000-01-20') because DateTime::sub is not static. You have to create the DateTime object first.


<?php $dateA = date_sub('2000-01-20', date_interval_create_from_date_string('10 days')); ?>

will be replace by
= new DateTime('2000-01-20');
$dateA = $dateB->sub(date_interval_create_from_date_string('10 days'));
To Top