tags:

views:

22

answers:

2

I was playing around with this http://www.phpform.org/ to create a form.

One of form html is the following.

I am not sure what kind of type I should use it for HH, MM and AM/PM.

Should I use TINYINT with 2 length for HH, MM and VARCHAR with 2 length for AM/PM?

Should I have separate field for each?

...
...
<li id="li_1" >
        <label class="description" for="element_1">Time </label>
        <span>
            <input id="element_1_1" name="element_1_1" class="element text " size="2" type="text" maxlength="2" value=""/> : 
            <label>HH</label>
        </span>
        <span>
            <input id="element_1_2" name="element_1_2" class="element text " size="2" type="text" maxlength="2" value=""/> : 
            <label>MM</label>
        </span>
        <span>
            <input id="element_1_3" name="element_1_3" class="element text " size="2" type="text" maxlength="2" value=""/>
            <label>SS</label>
        </span>
        <span>
            <select class="element select" style="width:4em" id="element_1_4" name="element_1_4">
                <option value="AM" >AM</option>
                <option value="PM" >PM</option>
            </select>
            <label>AM/PM</label>
        </span> 
        </li>   

Thanks in advance.

+1  A: 

Store it as a regular 24 hour HH:MM:SS (the mysql time type). Do the formatting when outputting. You can use TIME_FORMAT() to reformat it into AM/PM format:

mysql> SELECT TIME_FORMAT('22:22:22', '%r');
        -> '10:22:22 PM'
Emil H
+2  A: 

The three fields together represent a time. The most appropriate type for this would be TIME. There's no need to keep them separate and it makes your database more complex than it needs to be.

Richard Fearn