A
A
Alexey selftrips.ru2018-04-21 15:45:48
PHP
Alexey selftrips.ru, 2018-04-21 15:45:48

How to change the year of a date?

the date is given as a string variable, say 6.7.2018
How to change the year? Let's say 3 years ago.
those. get value 6.7.2015
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zhainar, 2018-04-21
@selftrips

$d = new DateTime('6.7.2018');
$d->modify('-3 years');

var_dump($d);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question