PHP date/time help/
Posted
by
NOW
on Stack Overflow
See other posts from Stack Overflow
or by NOW
Published on 2011-01-14T18:35:12Z
Indexed on
2011/01/14
18:53 UTC
Read the original article
Hit count: 150
php
I keep getting a value of 0 for $years
and $months
when there should be a value other then 0 can someone tell me what I'm doing wrong with my code? And what I need to fix?
I'm trying to subtract two dates.
Here is my PHP code.
$delete_date = "2000-01-12 08:02:39";
$current_date = date('Y-m-d H:i:s'); //current date
$diff = abs(strtotime($current_date) - strtotime($delete_date));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
echo $current_date . '<br />';
echo $delete_date. '<br />';
echo $diff. '<br />';
echo $years. '<br />';
echo $months. '<br />';
© Stack Overflow or respective owner