Showing posts with label calculate between tow days. Show all posts
Showing posts with label calculate between tow days. Show all posts

Friday 18 May 2018

Calculate Number of days Between two dates except saturday & sunday or week off in PHP script


<?php
$strt_date = date_create('2015-m-1');
$end_date = date_create(date('Y-m-d'));
date_sub($strt_date, date_interval_create_from_date_string('1 day'));
$interval = date_diff($strt_date, $end_date);
$num=$interval->format('%a');
$x=1;
for($i=0;$i<$num;$i++){
  date_add($strt_date, date_interval_create_from_date_string('1 day'));
  $next_day=date_format($strt_date, 'd-m-Y');
  echo "<br>";
  $new_date = new DateTime($next_day);
  $weeknum=$new_date->format('w');
  if(($weeknum!=0)&&($weeknum!=6)){
	 echo "$x. not a holiday :$weeknum  $next_day ";
	 $x++;
  }
}
?>