Home > PHP > How to calculate the list of dates between two dates

How to calculate the list of dates between two dates

In this post i want to explain how to calculate the list of dates between two dates using php code. Just we have to give the starting date and ending date and this function will calculate the dates including leap year and monthly days … It will be mainly useful in the calculate the statistics or register users between given dates.

How to calculate the list of dates between two dates | Anil Labs

How to calculate the list of dates between two dates | Anil Labs

 

PHP Code:

 

<?php
$fromDate = "02/14/1983"; // month / day / year
$toDate = "06/07/2011";  // month / day / year

$dateMonthYearArr = array();
$fromDateSTR = strtotime($fromDate);
$toDateSTR = strtotime($toDate);

for ($currentDateSTR = $fromDateSTR; $currentDateSTR <= $toDateSTR; $currentDateSTR += (60 * 60 * 24)) {
// use date() and $currentDateSTR to format the dates in between
$currentDateStr = date("Y-m-d",$currentDateSTR);
$dateMonthYearArr[] = $currentDateStr;
//print $currentDateStr."<br />";
}


print_r($dateMonthYearArr);


?>

Hope this will be useful.

You may also like
Multi-language support for web application with MySql and PHP
How to add or remove file fields using jquery
How to calculate statistics in daily, weekly , monthly and yearly using php
How to rectify json_encode returns null in php web services

5 Responses

  1. Pingback : How to calculate statistics in daily, weekly , monthly and yearly using php - Anil Labs

  2. Pingback : How to calculate statistics in daily – LIMAS

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.