No this is not the standard +86400 seconds between dates.
$start_time = strtotime("2012-01-15 23:59");
$end_time = strtotime("2012-01-16 00:05");
$daysInBetweenTimestamps = ?
That is the problem I'm currently facing as the timestamps may range in between a 5 minute to 5 hour time span for instance, using standard +86400 to see if it's more than a day would not work, and due to massive amount of indexing that I'm doing I would like to see if there is a more efficient way to check if a new day has started instead of doing a date("d") > $prevDay on the second level.
Updating with the test for the first example:
echo "Absolute Start: ".date("Y-m-d H:i:s",$start)."<br />";
echo "Absolute End: ".date("Y-m-d H:i:s",$end)."<br />";
echo "Interval Used: $interval(seconds) OR ".($interval / 60)."(minutes)<br />";
$numberOfIntervals = ceil(($end - $start) / $interval);
echo "Number of intervals:$numberOfIntervals<br /><br />";
if ($numberOfIntervals > 0){
for ($i = 0; $i < $numberOfIntervals; $i++){
$curStart = $start + ($interval * $i);
$curEnd = $curStart + $interval;
if ($curEnd > $end){$curEnd = $end;}
echo "Interval Start DateTime: ".date("Y-m-d H:i:s",$curStart)."<br />";
echo "Interval End DateTime: ".date("Y-m-d H:i:s",$curEnd)."<br />";
/* EXAMPLE PHP5.3 DateTime START - NOT WORKING */
$startDiff = new DateTime("@$curStart");
$endDiff = new DateTime("@$curEnd");
$diff = $startDiff->diff($endDiff);
echo $diff->format("%a") . " days<br />";
if ($diff->format("%a") > 0){
/* EXAMPLE PHP5.3 DateTime END */
/* EXAMPLE Julian START - WORKS */
$days = unixtojd($curEnd) - unixtojd($curStart);
echo "Number of days:$days<br />";
if ($days > 0){
/* EXAMPLE Julian END */
// Multiple days so the log files are split
echo "Multiple days so log files are split<br />";
}else{
echo "Single day so log files are NOT split<br />";
}
}
}
Output looks as follows:
Absolute Start: 2012-01-25 23:59:00
Absolute End: 2012-01-26 00:02:00
Interval Used: 180(seconds) OR 3(minutes)
Number of intervals:1
Interval Start DateTime: 2012-01-25 23:59:00
Interval End DateTime: 2012-01-26 00:02:00
=== EXAMPLE 1 START ===
0 days
Single day so log files are NOT split
Am I just missing something on the diff?
=== EXAMPLE 1 END ===
=== EXAMPLE 3 START ===
Number of days:1
Multiple days so log files are split
=== EXAMPLE 3 END ===
if (date("d",$end_time) > date("d",$start_time)){$multiDays = true;}
And then do the final second count of each day and loop between them, is this the most efficient way?` – Interview$cmd = "cat /var/log/httpd/access_log." . date("Y", $current_index) . "." . date("m", $current_index) . "." . date("d", $current_index) . "|sed -n \"/$strDate\ $start_time/,/$strDate\ $end_time/p\""; $return = exec($cmd,$returnValue);
So I basically use sed between time spans to do all the work for me, but I do have to know if there is a change in actual filename – Interview