Mysql

how to insert hour and minute in the mysql database… the hour and minute each one having a dropdown list while we select a time and minute it will store to database…how it will be done pl tell me any suggestion…i have used varchar datatype…i need HH:MM format only no need to display seconds…pl clarify my doubt as soon as possible

Here’s a quick demo to get you going. :wink:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>
    Demo
  </title>
</head>
  <body>
    
    <form action="" method="post">
      
      <select name="hour">
        <?php foreach(range(0, 23) as $hour): ?>
          <?php printf('<option value="&#37;1$02d">%1$02d</option>', $hour); ?>
        <?php endforeach; ?>
      </select>
      
      <select name="minute">
        <?php foreach(range(5, 55, 5) as $minute): ?>
          <?php printf('<option value="%1$02d">%1$02d</option>', $minute); ?>
        <?php endforeach; ?>
      </select>
      
      <input type="submit" value="Submit" />
      
    </form>
    
    <?php if('POST' === $_SERVER['REQUEST_METHOD']): ?>
      <?php printf("<pre>SQL: INSERT INTO table (selected_time) VALUES ('%02d:%02d');</pre>", $_POST['hour'], $_POST['minute']); ?>
    <?php endif; ?>
    
  </body>
</html>

Use the TIME datatype, not VARCHAR. :wink: