首页 > 解决方案 > How to enable date input and re format it ready for mysqli insert or select

问题描述

I am wanting to allow the date input in a html form to be

UK Format - DD/MM/YYYY , when submitted, before any php code is executed in the sense of queries... e.g. select, insert etc etc...

I want php to change the date inputted DD/MM/YYYY to YYYY-MM-DD

HTML

<div class="form-group col-mb-3">
    <label for="betDate"> Date</label>
      <input type="text" class="form-control" name="Date" id="Date" placeholder="Date" value="">
  </div>

  <div class="form-group col-mb-3">
    <label for="sport">Sport</label>
      <input type="text" class="form-control" name="sport" id="sport" placeholder="sport" >
  </div>

标签: phphtmlmysqli

解决方案


在您的输入中使用“日期”类型,您还可以限制允许设置的日期范围。

<input type="date" min="2019-02-01" max="2019-02-02">

您将看到正在观看该网站的国家/地区的格式,例如伦敦,当您使用 php 发送表单时,将(始终)将其转换为数据库格式(yyyy-mm-dd)。


推荐阅读