Avatar ·

How to calculate the difference between two dates in PHP?

Hello everyone! I'm a beginner PHP developer, and I have a problem with calculating the difference between two dates. I need to create functionality for calculating a user's age on the site. I have a birth date in the format '1990-05-15' and the current date. I'm trying to calculate the difference in years, months, and days. I tried using simple arithmetic operations, but I get strange results. For example, I subtract one date from another, and I get a number that doesn't match the expected difference. Here's my code: ```php $birthday = '1990-05-15'; $today = date('Y-m-d'); $diff = $today - $birthday; echo $diff; // Outputs something unclear, for example 24 ``` I understand that this is wrong because strings cannot be subtracted like that. I tried converting to timestamp using strtotime(), but the result