$t1 = strtotime('2013-07-01 00:00:00'); $t2 = strtotime('2013-07-10 23:59:59'); $s = strtotime('2013-07-05 00:00:00'); $e = strtotime('2013-07-15 23:59:59'); $xs = date( 'Y-m-d H:i:s', $t1 > $s ? $t1 : $s ); $xe = date( 'Y-m-d H:i:s', $t2 < $e ? $t2 : $e ); if( ($s >= $t1 && $s < = $t2) || ($t1 >= $s && $t1 < = $e) ){ echo $xs, ' ', $xe, "\r\n"; } $xs = $t1 > $s ? $t1 : $s ; $xe = $t2 < $e ? $t2 : $e ; if($xs <= $xe){ echo date('Y-m-d H:i:s', $xs), ' ', date('Y-m-d H:i:s', $xe), "\r\n"; }