title: Convert user input date in PHP form to MySQL acceptable format
body: <p>So, I know this type of question has been asked a lot, but I'm super new to MySql and PHP, so  forgive me for asking for details.</p>
  <p>I'm working on learning them, and I'm modifying a walkthrough I found on YouTube to change it from inputting pizza types, to creating a online event schedule page, where you can both submit new panels into a MySql database, as well as list all the event already in the database.</p>
  <p>The submission page is a PHP form, which is connected to the DB.  I'm struggling with three of the columns.  Panel Date, Panel Start Time, and Panel End Time.  Date is a DATE formart in the DB, and the two time columns have a TIME format in the database.</p>
  <p>I know the stardard for MySQL is YYYY-MM-DD for DATE, and HH:MM:SS in 24 hour format for time.  I have multiple questions about best way/how should this be done, so forgive me for the long list?</p>
  <p>1: Would it be better to have the user manually input the date and times, and just use a REGEX to confirm it follows one specific format?  I'm assuming just force them to input the date and time following the MySQL format, but I have no clue how to write the RegEx to make sure it's in the correct format, or</p>
  <p>2: Should I make it so there is a calendar button they can click on for the date to select the date from a calendar, and drop down lists for the time.  I have no clue how to make either of these things take the place of the text box that's already there for input.</p>
  <p>On the flip side, I have a couple questions about changing how the date shows on the page where it displays all the panels that are currently in the DB.</p>
  <p>3: What kind of statement would I use to convert the date from YYYY-MM-DD to MM-DD-YYYY before it's displayed, and do the same kind of this for the times (convert the from 24 hour to 12 hour with AM or PM after them.</p>
  <p>I'm going to include the code I have so far.  Like I said before, I'm sure there's a lot of things I could clean up in it, but for right now I'm just trying to get this Date/Time thing fixed.</p>
  <p>Here is the home page/where the data that is currently in the database is displayed, and where question 3 applies.</p>
  <pre><code>&lt;?php 
  
    $conn = mysqli_connect('localhost', 'eventeny', 'test1234', 'test_event');
  
    if(!$conn){
      echo 'Connection error: '. mysqli_connect_error();
    }
  
    $sql = 'SELECT panelName, panelDescription, panelDate, panelStartTime, panelEndTime, panelModerator, panelist FROM schedule ORDER BY panelDate, panelStartTime, panelName';
  
    $result = mysqli_query($conn, $sql);
  
    $fullSchedule = mysqli_fetch_all($result, MYSQLI_ASSOC);
  
    mysqli_free_result($result);
  
    mysqli_close($conn);
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    
    &lt;head&gt;
    &lt;title&gt;Test Event 2022&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css&quot;&gt;
    &lt;style type=&quot;text/css&quot;&gt;
      .brand{
        background: #cbb09c !important;
      }
      .brand-text{
        color: #cbb09c !important;
      }
      form{
        max-width: 460px;
        margin: 20px auto;
        padding: 20px;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body class=&quot;grey lighten-4&quot;&gt;
    &lt;nav class=&quot;white z-depth-0&quot;&gt;
      &lt;div class=&quot;container&quot;&gt;
        &lt;a href=&quot;index.php&quot; class=&quot;brand-logo brand-text&quot;&gt;Event Schedule&lt;/a&gt;
        &lt;ul id=&quot;nav-mobile&quot; class=&quot;right hide-on-small-and-down&quot;&gt;
          &lt;li&gt;&lt;a href=&quot;add.php&quot; class=&quot;btn brand z-depth-0&quot;&gt;Add a panel&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/nav&gt;
  
    &lt;h4 class=&quot;center grey-text&quot;&gt;Schedule&lt;/h4&gt;
  
    &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
  
        &lt;?php foreach($fullSchedule as $schedule): ?&gt;
  
          &lt;div class=&quot;col s6 m4&quot;&gt;
            &lt;div class=&quot;card z-depth-0&quot;&gt;
              &lt;div class=&quot;card-content center&quot;&gt;
                &lt;h6&gt;&lt;?php echo htmlspecialchars($schedule['panelName']); ?&gt;&lt;/h6&gt;
                &lt;div&gt;&lt;?php echo htmlspecialchars($schedule['panelDate']); ?&gt;&lt;/div&gt;
                &lt;div&gt;&lt;?php echo htmlspecialchars($schedule['panelStartTime']); ?&gt; - &lt;?php echo htmlspecialchars($schedule['panelEndTime']); ?&gt;&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;card-action right-align&quot;&gt;
                &lt;a class=&quot;brand-text&quot; href=&quot;details.php?id=&lt;?php echo $pizza['id'] ?&gt;&quot;&gt;more info&lt;/a&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
  
        &lt;?php endforeach; ?&gt;
  
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;footer class=&quot;section&quot;&gt;
      &lt;div class=&quot;center grey-text&quot;&gt;&amp;copy; Copyright 2021&lt;/div&gt;
    &lt;/footer&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  <p>And here is the page where they will be able input new events into the database.  This is where I need the date and time to get looked at, make sure it's in the correct format (whatever that may be), and then save it into the database</p>
  <pre><code>&lt;?php
  
      $conn = mysqli_connect('localhost', 'eventeny', 'test1234', 'test_event');
  
    if(!$conn){
      echo 'Connection error: '. mysqli_connect_error();
    }
  
      $panelName = $panelDescription = $panelDate = $panelStartTime = $panelEndTime = $panelModerator = $panelist = '';
      
      $errors = array('panelName'=&gt;'', 'panelDescription'=&gt;'', 'panelDate'=&gt;'', 'panelStartTime'=&gt;'', 'panelEndTime'=&gt; '', 'panelModerator'=&gt;'', 'panelist'=&gt;'');
  
          if(isset($_POST['submit'])){
  
          if(empty($_POST['panelName'])){
              $errors['panelName'] = 'A panel name is required.';
          } else{
              $panelName = $_POST['panelName'];
              }
  
          if(empty($_POST['panelDescription'])){
              $errors['panelDescription'] = 'A panel description is required.';
          } else{
              $panelDescription = $_POST['panelDescription'];
              }
  
          if(empty($_POST['panelDate'])){
              $errors['panelDate'] = 'The date of the panel is required.';
          } else{
              $panelDate = $_POST['panelDate'];
              }
  
          if(empty($_POST['panelStartTime'])){
              $errors['panelStartTime'] = 'The starting time of the panel is required.';
          } else{
              $panelStartTime = $_POST['panelStartTime'];
              }
  
          if(empty($_POST['panelEndTime'])){
              $errors['panelEndTime'] = 'The ending of the panel is required.';
          } else{
              $panelEndTime = $_POST['panelEndTime'];
              }
  
          if(empty($_POST['panelModerator'])){
              $errors['panelModerator'] = 'The name of the panel moderator is required.';
          } else{
              $panelModerator = $_POST['panelModerator'];
              }
  
          if(empty($_POST['panelist'])){
              $errors['panelist'] = 'The name(s) of the panelist(s) are required.';
          } else{
              $panelDate = $_POST['panelist'];
              }
  
          if(!array_filter($errors)){
              $panelName = mysqli_real_escape_string($conn, $_POST['panelName']);
              $panelDescription = mysqli_real_escape_string($conn, $_POST['panelDescription']);
              $panelDate = mysqli_real_escape_string($conn, $_POST['panelDate']);
              $panelStartTime = mysqli_real_escape_string($conn, $_POST['panelStartTime']);
              $panelEndTime = mysqli_real_escape_string($conn, $_POST['panelEndTime']);
              $panelModerator = mysqli_real_escape_string($conn, $_POST['panelModerator']);
              $panelist = mysqli_real_escape_string($conn, $_POST['panelist']);
  
              $sql = &quot;INSERT INTO schedule(panelName,panelDescription,panelDate,panelStartTime,panelEndTime,panelModerator,panelist) VALUES('$panelName','$panelDescription','$panelDate'.'$panelStartTime','$panelEndTime','$panelModerator','$panelist')&quot;;
  
              if(mysqli_query($conn, $sql)){
                  header('Location: add.php');
              } else {
                  echo 'query error: '. mysqli_error($conn);
              }
  
              
          }
  
      }
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    
    &lt;head&gt;
    &lt;title&gt;Test Event 2022&lt;/title&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css&quot;&gt;
    &lt;style type=&quot;text/css&quot;&gt;
      .brand{
        background: #cbb09c !important;
      }
      .brand-text{
        color: #cbb09c !important;
      }
      form{
        max-width: 460px;
        margin: 20px auto;
        padding: 20px;
      }
    &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body class=&quot;grey lighten-4&quot;&gt;
    &lt;nav class=&quot;white z-depth-0&quot;&gt;
      &lt;div class=&quot;container&quot;&gt;
        &lt;a href=&quot;index.php&quot; class=&quot;brand-logo brand-text&quot;&gt;Event Schedule&lt;/a&gt;
        &lt;ul id=&quot;nav-mobile&quot; class=&quot;right hide-on-small-and-down&quot;&gt;
          &lt;li&gt;&lt;a href=&quot;add.php&quot; class=&quot;btn brand z-depth-0&quot;&gt;Add a panel&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/nav&gt;
  
      &lt;section class=&quot;container grey-text&quot;&gt;
          &lt;h4 class=&quot;center&quot;&gt;Add a Panel&lt;/h4&gt;
          &lt;form class=&quot;white&quot; action=&quot;add.php&quot; method=&quot;POST&quot;&gt;
              &lt;label&gt;Panel Name&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelName&quot; value=&quot;&lt;?php echo htmlspecialchars($panelName) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelName']; ?&gt;&lt;/div&gt;
              &lt;label&gt;Panel Description&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelDescription&quot; value=&quot;&lt;?php echo htmlspecialchars($panelDescription) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelDescription']; ?&gt;&lt;/div&gt;
              &lt;label&gt;Panel Date (Must be in YYYY-MM-DD format)&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelDate&quot; value=&quot;&lt;?php echo htmlspecialchars($panelDate) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelDate']; ?&gt;&lt;/div&gt;
              &lt;label&gt;Panel Start Time (Must be in 24 hour HH:MM:SS format&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelStartTime&quot; value=&quot;&lt;?php echo htmlspecialchars($panelStartTime) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelStartTime']; ?&gt;&lt;/div&gt;
              &lt;label&gt;Panel End Time&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelEndTime&quot; value=&quot;&lt;?php echo htmlspecialchars($panelEndTime) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelEndTime']; ?&gt;&lt;/div&gt;
              &lt;label&gt;Panel Moderator&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelModerator&quot; value=&quot;&lt;?php echo htmlspecialchars($panelModerator) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelModerator']; ?&gt;&lt;/div&gt;
              &lt;label&gt;Panelist(s)&lt;/label&gt;
              &lt;input type=&quot;text&quot; name=&quot;panelist&quot; value=&quot;&lt;?php echo htmlspecialchars($panelist) ?&gt;&quot;&gt;
              &lt;div class=&quot;red-text&quot;&gt;&lt;?php echo $errors['panelist']; ?&gt;&lt;/div&gt;
              &lt;div class=&quot;center&quot;&gt;
                  &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;btn brand z-depth-0&quot;&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/section&gt;
  
      &lt;footer class=&quot;section&quot;&gt;
          &lt;div class=&quot;center grey-text&quot;&gt;&amp;copy; Copyright 2021&lt;/div&gt;
      &lt;/footer&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  <p>If anyone can give me suggestions on how to do this, and hopefully walk me through it at least a little, I would greatly appreciate it.  This is the last part I'm struggling with, and I just can't get it to work.</p>