Convert text input to date or datetime for MySQL

Getting confused about converting string format dates/datetimes for adding to MySQL table.

I have linked a JQuery datetime picker to text fields in the PHP/HTML code, and the dates in the fields are formatted as UK format dd/mm/yyyyy and dd/mm/yyyy hh:ss (e.g. “25/12/2020” and “25/12/2020 11:59”) .

After the form post
$dt =$_POST[“accdatetime”];
$d=$_POST[“accdate”]
$d now = “25/12/2020” and $dt = “25/12/2020 11:59”
which is what I expect to see.

How do I convert those two values into a format allows $dt to be inserted into a MySQL Datetime column and $d into a Date column?

Sorted it by writing function to convert dd/mm/yyyy format string to a yyyy-mm-dd format string and this string loads directly to the MySQL Datetime or Date column without any conversion.
Assume there is a “proper” way of doing this, but can’t find it.

Sponsor our Newsletter | Privacy Policy | Terms of Service