“Dapatkan jumlah hari antara dua tanggal dalam PHP” Kode Jawaban

Perbedaan PHP antara dua tanggal dalam beberapa tahun dan hari

//get Date diff as intervals 
$d1 = new DateTime("2018-01-10 00:00:00");
$d2 = new DateTime("2019-05-18 01:23:45");
$interval = $d1->diff($d2);
$diffInSeconds = $interval->s; //45
$diffInMinutes = $interval->i; //23
$diffInHours   = $interval->h; //8
$diffInDays    = $interval->d; //21
$diffInMonths  = $interval->m; //4
$diffInYears   = $interval->y; //1

//or get Date difference as total difference
$d1 = strtotime("2018-01-10 00:00:00");
$d2 = strtotime("2019-05-18 01:23:45");
$totalSecondsDiff = abs($d1-$d2); //42600225
$totalMinutesDiff = $totalSecondsDiff/60; //710003.75
$totalHoursDiff   = $totalSecondsDiff/60/60;//11833.39
$totalDaysDiff    = $totalSecondsDiff/60/60/24; //493.05
$totalMonthsDiff  = $totalSecondsDiff/60/60/24/30; //16.43
$totalYearsDiff   = $totalSecondsDiff/60/60/24/365; //1.35
Grepper

Dapatkan jumlah hari antara dua tanggal dalam PHP

$startDate = new DateTime("2019-10-27");
$endDate = new DateTime("2020-04-11");

$difference = $endDate->diff($startDate);
echo $difference->format("%a");
vmxes

php dapatkan hari diff

$now = time(); // or your date as well
$your_date = strtotime("2010-01-31");
$datediff = $now - $your_date;

echo round($datediff / (60 * 60 * 24));
Nervous Nightingale

Dapatkan 2 hari sebelum tanggal dalam PHP

date('Y/m/d',strtotime("-1 days"));

Or Use DateTime class like this-

$date = new DateTime();
echo $date->modify("-1 days")->format('Y-m-d');
Long Leopard

Temukan hari dengan nama antara dua tanggal dalam PHP

$from_date ='01-01-2013';
$to_date ='05-01-2013';

$from_date = new DateTime($from_date);
$to_date = new DateTime($to_date);

for ($date = $from_date; $date <= $to_date; $date->modify('+1 day')) {
  echo $date->format('l') . "\n";
}
Careful Coyote

Jawaban yang mirip dengan “Dapatkan jumlah hari antara dua tanggal dalam PHP”

Pertanyaan yang mirip dengan “Dapatkan jumlah hari antara dua tanggal dalam PHP”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya