Jump to content

Divide a single date


ajithsk

Recommended Posts

so essenetially you want to split a 24hour period equally and show it as a timestamp? or something like that? although your example does exclude the first minute of said period.

 

I am guessing this split could be 2,3 ,4 or more? thus becoming 12hr,8hr,6hr etc periods?

 

 

 

Sanity prevails

 

<?php
    $numdivs = 3; // or however many you need
    
    $divsecs = 86400/$numdivs;
    
    $basedate = '2010-01-01';
    $basetime = strtotime($basedate);
    
    echo '<pre>';
    for($i=0; $i < $numdivs; $i++) {
        $t1 = $basetime + $i * $divsecs;
        $t2 = $t1 + $divsecs - 1;
        printf ('%s to %s<br>', date('d M Y H:i:s', $t1), date('H:i:s', $t2));
    }
    echo '</pre>';
?>

 

-->

 

01 Jan 2010 00:00:00 to 07:59:59

01 Jan 2010 08:00:00 to 15:59:59

01 Jan 2010 16:00:00 to 23:59:59

  Quote

Sanity prevails

 

Another reason I wanted to close this thread is because of this.  While this code does something, we have no way of knowing if it's what OP wanted.  the "problem" you solved was someone's random guess as to what OP could possibly have meant. 
  Quote

  Quote

Sanity prevails

 

Another reason I wanted to close this thread is because of this.  While this code does something, we have no way of knowing if it's what OP wanted.  the "problem" you solved was someone's random guess as to what OP could possibly have meant. 

 

At least it's a reasonable interpretation of his post, unlike some of the more inane comments. You should at least give the OP a chance to respond.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.