Link to home
Create AccountLog in
Avatar of brendan-amex
brendan-amex

asked on

MySQL Date Input

I'm building a PHP database front end with a MySQL backend and it's great, MySQL is perfect. Well almost. The way you enter dates here is not intuitive. I want to create some kind of mask that will allow me to enter a date as MM-DD-YYYY or MM/DD/YYYY and then have it resolve to YYYY-MM-DD. Any help is appreciated.
Avatar of Hugh McCurdy
Hugh McCurdy
Flag of United States of America image

You can start by using strtotime()  

http://www.w3schools.com/php/php_ref_date.asp
http://www.w3schools.com/php/func_date_strtotime.asp

Then you can use date() to format the date however you want.
http://www.w3schools.com/php/func_date_date.asp
ASKER CERTIFIED SOLUTION
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of brendan-amex
brendan-amex

ASKER

fishboy - thank you. that's a great option. I have it on my site but I want to be able to remove the drop down for format options and have the default be the second option yy-mm-dd to match MySQL, do you know how I can change the default so I can remove the dropdown? If I remove the dropdown now, it reverts back to the mm/dd/yy default.
Ignore that. I figured it out. Thank you! A+
You are welcome