Finding the number of days between two dates

2018-12-31 03:09发布

How to find number of days between two dates using PHP?

标签: php
26条回答
唯独是你
2楼-- · 2018-12-31 04:12

You can find dates simply by

<?php
$start  = date_create('1988-08-10');
$end    = date_create(); // Current time and date
$diff   = date_diff( $start, $end );

echo 'The difference is ';
echo  $diff->y . ' years, ';
echo  $diff->m . ' months, ';
echo  $diff->d . ' days, ';
echo  $diff->h . ' hours, ';
echo  $diff->i . ' minutes, ';
echo  $diff->s . ' seconds';
// Output: The difference is 28 years, 5 months, 19 days, 20 hours, 34 minutes, 36 seconds

echo 'The difference in days : ' . $diff->days;
// Output: The difference in days : 10398
查看更多
ら面具成の殇う
3楼-- · 2018-12-31 04:13

If you have the times in seconds (I.E. unix time stamp) , then you can simply subtract the times and divide by 86400 (seconds per day)

查看更多
登录 后发表回答