Avatar ·

Calculating the number of days between two dates in PHP

Hello everyone! I'm new to PHP and writing a small script for task tracking. I need to calculate how many days have passed between two dates. For example, I have a task start date: "2023-10-01" and an end date: "2023-10-25". I want to get the difference in days. I tried using simple string subtraction, but it doesn't work because PHP can't subtract strings. Then I converted the dates to timestamps using strtotime(), subtracted one from the other, and divided by 86400 (the number of seconds in a day). Here's an example of my code: ```php $start = '2023-10-01'; $end = '2023-10-25'; $diff = (strtotime($end) - strtotime($start)) / 86400; echo $diff; ``` But I noticed that sometimes the result comes out with a fractional part (e.g., 24.958333) instead of a whole number. I've also heard that due to daylight saving time changes...