rondog Posted June 8, 2009 Share Posted June 8, 2009 Can anyone help me think of a way to generate a time code string? I need the format like this: "00:00:00.00" "00:00:10.00" "00:00:20.00" "00:00:30.00" ------- "00:50:10.00" "00:50:20.00" "00:50:30.00" etc... I need to basically make a loop that will add $seconds (I can make this whatever..in my example is 10 seconds) and continue for X amount of loops. I realized this will be a very long loop. I am just using it to copy/paste this information so I dont have to type it all. Link to comment https://forums.phpfreaks.com/topic/161382-solved-help-generate-time-code/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 8, 2009 Share Posted June 8, 2009 <?php // generate a list of date/time values function add_interval($datetime,$interval){ return date('Y-m-d H:i:s',strtotime("$datetime + $interval")); } // end of add_interval function $interval = '30 seconds'; // format that strtotime() can use, the resolution of the display grid (15 min, 30 min, 1hr, 2hr...) - should be evenly divisible into the next higher unit $display_start = '2009-05-14 00:00:00'; // the datetime to start the display $display_stop = '2009-05-14 00:50:30'; // the datetime to stop the display for($i = $display_start; $i <= $display_stop; $i = add_interval($i,$interval)){ // $i is a datetime yyyy-mm-dd hh:mm:ss //echo "$i.00<br />"; echo substr($i, - . ".00<br />"; // get the hh:mm:ss.00 portion of the value } ?> Link to comment https://forums.phpfreaks.com/topic/161382-solved-help-generate-time-code/#findComment-851682 Share on other sites More sharing options...
rondog Posted June 8, 2009 Author Share Posted June 8, 2009 perfect! Thanks so much Link to comment https://forums.phpfreaks.com/topic/161382-solved-help-generate-time-code/#findComment-851690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.