Stanislas Piotrowski
Stanislas Piotrowski

Reputation: 2694

html5 input type date

I'm trying to change dat format on google chrome because my mysql request doesnot work using that format YYYY/MM//DD is there a way to change this '/' by this '-' ?

I was looking on the internet several hours, but I did not find any way.

does anyone know how it is possible?

Kind regards.

SP

Upvotes: 1

Views: 1526

Answers (1)

Jose Salvatierra
Jose Salvatierra

Reputation: 2525

Assuming the HTML5 date field is called 'date' and gets passed through GET, the php code to change the date would be the following.

$dat = new DateTime($_GET['date']);
$new_format = $dat->format('Y-m-d H:i:s');

That's it! Fairly simple, you then pass the $new_format variable as datetime to SQL.

Upvotes: 2

Related Questions