Showing posts with label between two dates. Show all posts
Showing posts with label between two dates. Show all posts

Monday, 18 August 2014

How to take dates between two dates in php?

   $task_to_do = array();
   echo "
"; $s = strtotime("START_DATE"); $d = strtotime("END_DATE"); $dif = 86400; $i=$s; $x=0; while ($i <= $d) { $dat = date("Y-m-d 00:00:00",$i); $t_s = date("Y-m-d 00:00:00",strtotime($dat)); $t_e = date("Y-m-d 23:59:59",strtotime($dat)); $task_to_do[$x]["start_date"] = $t_s; $task_to_do[$x]["end_date"] = $t_e; $i = $i+$dif; $x++; } echo "
";
   print_r($task_to_do);

Saturday, 28 June 2014

PHP - Mysql Get date between two date ranges

Fetching records between two date ranges
Between two years
SELECT * FROM `dt_tb` WHERE year( dt2 ) between 2004 and 2005
Between two month ranges. 
SELECT * FROM `dt_tb` WHERE month(dt) between '02' and '08'

SELECT * FROM `dt_tb` WHERE month(dt) between '02' and '08' and year(dt) between 2004 and 2005

Between two date ranges
SELECT * FROM `dt_tb` WHERE dt BETWEEN '2005-01-01' AND '2005-12-31'