How to find number of days between two dates using PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Easy to using date_diff
and, if needed:
If you want to echo all days between the start and end date, I came up with this :
Convert your dates to unix timestamps, then substract one from the another. That will give you the difference in seconds, which you divide by 86400 (amount of seconds in a day) to give you an approximate amount of days in that range.
If your dates are in format
25.1.2010
,01/25/2010
or2010-01-25
, you can use thestrtotime
function:Using
ceil
rounds the amount of days up to the next full day. Usefloor
instead if you want to get the amount of full days between those two dates.If your dates are already in unix timestamp format, you can skip the converting and just do the
$days_between
part. For more exotic date formats, you might have to do some custom parsing to get it right.