Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting php date to fit mysql database

Tags:

php

mysql

I want to convert an input date in the form of dd/mm/yyyy to the MySQL format which is yyyy-mm-dd.
I was trying to use date('Y-m-d', strtotime($_POST['date'])) but the problem is that the output is always Y-d-m, I think because it considers my 2nd argument to be mm/dd/yyyy.

How do I solve that?

like image 219
Mohamed Khamis Avatar asked Jul 13 '26 05:07

Mohamed Khamis


1 Answers

date('Y-m-d', strtotime(str_replace('/', '-', $_POST['date'])))
like image 116
dqhendricks Avatar answered Jul 14 '26 17:07

dqhendricks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!