Wie findet man die Anzahl der Tage zwischen zwei Daten mit PHP?
Antworten
Zu viele Anzeigen?
zmbush
Punkte
2764
Gratian
Punkte
47
Anis KCHAOU
Punkte
365
Dieser Code funktionierte bei mir und wurde mit der PHP 8 Version getestet:
function numberOfDays($startDate, $endDate)
{
//1) converting dates to timestamps
$startSeconds = strtotime($startDate);
$endSeconds = strtotime($endDate);
//2) Calculating the difference in timestamps
$diffSeconds = $startSeconds - $endSeconds;
//3) converting timestamps to days
$days=round($diffSeconds / 86400);
/* note :
1 day = 24 hours
24 * 60 * 60 = 86400 seconds
*/
//4) printing the number of days
printf("Difference between two dates: ". abs($days) . " Days ");
return abs($days);
}
premkumar
Punkte
81
Love Kumar
Punkte
920