How to save user-supplied date in MySQL?

3

I have a form that has a field where the user's date of birth is entered, this field has a datepicker that already returns the date in year, month, day format, this date is accessed through $_GET['birthdate'] its format is string , so my question is how to insert it into the database? Do I have to assign this date to an intermediate object?

    
asked by anonymous 07.02.2015 / 13:51

1 answer

6

It would look like this:

$date = date("Y-m-d", strtotime($_GET['birthdate'])); //converte para tipo date
mysqli_query($conexao, "INSERT INTO tabela (birthday) VALUES ($date)");

See working on ideone . as far as possible

MySQL Documentation on Dates .

strtotime documentation.

date documentation.

Note that the string date must be in a format minimally recognizable by PHP. Otherwise you will either fail or need to make a more complete parse to identify it.

    
07.02.2015 / 15:05