Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Get the number of days between two dates in PHP

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

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

how to calculate days difference between two dates in php

// how to calculate days difference between two dates in laravel

use DateTime; // inside Controller Class

$startDate = new DateTime($request->start_date);
$endDate   = new DateTime($request->end_date);

$daysDifference = ($startDate->diff($endDate)->days);
Comment

How to calculate the difference between two dates php

$datetime1 	= new DateTime('2020-10-11 16:52:52');
$datetime2 	= new DateTime('2020-10-13 16:52:52');
$interval 	= $datetime1->diff($datetime2);

echo $interval->format('%a days');

$interval = $datetime1->diff($datetime2);
$diffInSeconds = $interval->s; 
$diffInMinutes = $interval->i; 
$diffInHours   = $interval->h; 
$diffInDays    = $interval->d; 
$diffInMonths  = $interval->m; 
$diffInYears   = $interval->y; 
Comment

Calculate the Difference Between Two Dates Using PHP

phpCopy$firstDate = "2019-01-01";
$secondDate = "2020-03-04";

$dateDifference = abs(strtotime($secondDate) - strtotime($firstDate));

$years  = floor($dateDifference / (365 * 60 * 60 * 24));
$months = floor(($dateDifference - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
$days   = floor(($dateDifference - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 *24) / (60 * 60 * 24));

echo $years." year,  ".$months." months and ".$days." days";

//output: 1 year, 2 months and 3 days
Comment

php get date between two dates

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')
);

//Which should get you an array with DateTime objects. 

//To iterate

foreach ($period as $key => $value) {
    //$value->format('Y-m-d')       
}
Comment

find days with name between two dates in 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') . "
";
}
Comment

Number of week days between two dates in php

You are given two string (dd-mm-yyyy) representing two date, 
you have to find number of all weekdays present in between given dates.
  
function number_of_days($days, $start, $end) {
	$start = strtotime($start); $end = strtotime($end);
	$w = array(date('w', $start), date('w', $end));
	$x = floor(($end-$start)/604800);
	$sum = 0;
	for ($day = 0;$day < 7;++$day) {
		if ($days & pow(2, $day)) {
			$sum += $x + ($w[0] > $w[1]?$w[0] <= $day || $day <= $w[1] : $w[0] <= $day && $day <= $w[1]);
		}
	}
	return $sum;
}

function getWeeklyDayNumbers($startDate, $endDate) {
	$weekdays = array('monday' => 0, 'tuesday' => 0, 'wednesday' => 0, 'thursday' => 0, 'friday' => 0, 'saturday' => 0, 'sunday' => 0);
	$weekdays['monday'] += number_of_days(0x02, $startDate, $endDate); // MONDAY
	$weekdays['tuesday'] += number_of_days(0x04, $startDate, $endDate); // TUESDAY
	$weekdays['wednesday'] += number_of_days(0x08, $startDate, $endDate); // WEDNESDAY
	$weekdays['thursday'] += number_of_days(0x10, $startDate, $endDate); // THURSDAY
	$weekdays['friday'] += number_of_days(0x20, $startDate, $endDate); // FRIDAY
	$weekdays['saturday'] += number_of_days(0x40, $startDate, $endDate); // SATURDAY
	$weekdays['sunday'] += number_of_days(0x01, $startDate, $endDate); // SUNDAY
	return $weekdays;
}

$weekdays = getWeeklyDayNumbers('01-01-2021', '31-01-2021');
print_r($weekdays);exit;
Comment

get number of days between two dates php

//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
Comment

get number of days between two dates php

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

echo round($datediff / (60 * 60 * 24));
Comment

php get all days between two dates

$period = new DatePeriod(
     new DateTime('2010-10-01'),
     new DateInterval('P1D'),
     new DateTime('2010-10-05')
);

foreach ($period as $key => $value) {
    //$value->format('Y-m-d')       
}
Comment

PREVIOUS NEXT
Code Example
Php :: php get uploaded file extension 
Php :: php copyright footer 
Php :: why css not working with php file 
Php :: wordpress thumbnail url 
Php :: pre_r 
Php :: echo query in laravel 
Php :: yii2 where in 
Php :: Fatal error: Maximum execution time of 120 seconds exceeded in 
Php :: wp safe redirect 
Php :: replace _ with space php 
Php :: laravel flutter save image in data 
Php :: php reload current page 
Php :: php put file in ftp server 
Php :: apache htaccess read from /public 
Php :: unique value when two columns laravel migration 
Php :: how to disable/hide menu admin page wordpress dev 
Php :: get contents of a tmp file php 
Php :: wordpress update post php 
Php :: wordpress print post data 
Php :: php check if extension is installed 
Php :: php compare strings case insensitive 
Php :: how can we use two php version in mac os 
Php :: laravel plural and singular 
Php :: laravel now date 
Php :: get all post meta 
Php :: disable edit-link storefront 
Php :: php median 
Php :: trim elements of array php 
Php :: get current route laravel 
Php :: php check if its a name 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =