M
M
Maxim2019-10-16 12:16:08
PHP
Maxim, 2019-10-16 12:16:08

How to get number of months?

How to subtract the current date from the date and get the number of months of difference between them?

$date = 02.12.2019;
 now = date('d.m.Y');
$d2 = strtotime($date);
$d1 = strtotime($now);
$diff = $d2-$d1;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2019-10-16
@migelbd

Something like this for example

$now = new DateTime('now');
$date = new DateTime('2019-05-01');
$diff = $now->diff($date);
$interval = $diff->format('%m');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question