Ejemplo 1: obtener el número de días entre dos fechas en PHP
$startDate=newDateTime("2019-10-27");$endDate=newDateTime("2020-04-11");$difference=$endDate->diff($startDate);echo$difference->format("%a");
Ejemplo 2: número de días de la semana entre dos fechas en 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.functionnumber_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]<=$dayreturn$sum;functiongetWeeklyDayNumbers($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);// SUNDAYreturn$weekdays;$weekdays=getWeeklyDayNumbers('01-01-2021','31-01-2021');print_r($weekdays);exit;
Comentarios y puntuaciones de la guía
Más adelante puedes encontrar las crónicas de otros creadores, tú asimismo tienes la habilidad dejar el tuyo si te gusta.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)