Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - How to count how many months from a specific date

Tags:

php

How can I count the number of months from the following two dates below using the Procedural style method?

PHP code.

$delete_date = "2000-01-12 08:02:39";
$current_date = date('Y-m-d H:i:s'); //current date
like image 431
HELP Avatar asked Feb 26 '23 09:02

HELP


1 Answers

You're looking for DateTime::diff?

$delete_date = "2000-01-12 08:02:39";
$date_format = 'Y-m-d H:i:s';
$current_date = date($date_format);
$diff = date_diff(date_create_from_format($date_format, $delete_date), date_create());
$months = $diff->m;

Something along the lines of that.

like image 156
Shadikka Avatar answered Mar 08 '23 10:03

Shadikka