Results 1 to 1 of 1

Thread: [RESOLVE] Parse MySQL time format HH:MM:SS into each variable

  1. #1
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [RESOLVE] Parse MySQL time format HH:MM:SS into each variable

    I have an select option in php that show the default as the selected time from database. The time format from MYSQL is HH:MM:SS, how do I separate them into each variable, $eventTimeHour = HH, $eventTimeMin =MM?

    Code:
     <?php
    	//Mysql code for connection and retrieving the result here;
    	// $eventTime is given as HH:MM:00
    	//how to parse them as $eventTimeHour = HH and $eventTimeMin = MM?
    	$eventTime = $row['TIME'];
    
    	for ($hr = 1; $hr < 13; $hr++)
        {
    		$hr = str_pad($hr, 2, '0', STR_PAD_LEFT);
    		if ($hr == $eventTimeHour)
    		{
    			echo "<option selected>$hr</option>";
    		}
    		else
    		{
        		echo "<option>$hr</option>";
    		}
    	 }
    
        </select>
    <select name="EventTimeMin" id="EventTimeMin">
    <?php
    	for ($min = 00; $min < 60; $min++)
        {
    		$min = str_pad($min, 2, '0', STR_PAD_LEFT);
    		if ($min == $eventTimeMin)
    		{
    			echo "<option selected>$min</option>";
    		}
    		else
    		{
        	echo "<option>$min</option>";
    		}
    	 }
    ?>
    edit: silly me, I remember the substr function and is using it to get the first 2 and 4th and 5th digits.
    Last edited by Wdblazer; 12-11-2010 at 11:04 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •