0

I have a script which i want to use to generate some data from a certain date. The problem i am having is setting the leading zero for minutes,hours and seconds.

For instance

<?php
for($i=0;$i<25;$i++){
    //echo $i.'<br/>';
    $start = "2012-10-01 $i:00:00";
    echo $start.'<br/>'; 
}
?>

I want all hours from 0 to 9 to have a leading zero. Is there a functions that can help me have the leading zero in hours,minutes or seconds?.

1 Answers1

0

Try str_pad

for($i=0;$i<25;$i++){
    $temp = str_pad($i,2,"0",STR_PAD_LEFT)
    $start = "2012-10-01 $temp:00:00";
    echo $start.'<br/>'; 
}

Demo

Ravi
  • 30,829
  • 42
  • 119
  • 173