1

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

1
  • Chromium doesn't even show a special input for type date; but the format is defined via the standard, so I guess it is a bug, when using / instead of - as a separator. Commented Aug 21, 2012 at 8:38

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

ok so there is no way to display it as I want, because fromm internet explorer to google chrome using safari or others it display YYYY-MM-DD or YYYY/MM/DD so I don't know becaue it really depends on which browser you are
In fact I have something like that $sql = 'INSERT INTO factures SET n_doss= "'.mysql_real_escape_string($_GET['n_doss']).'", libelle= "'.mysql_real_escape_string($_POST['libelle']).'", date_facture= "'.date('Ym-d',strtotime($_POST['date_facture'])).'", date_echue= "'.date('Y-m-d',strtotime($_POST['date_echue'])).'", montant= "'.mysql_real_escape_string($_POST['montant']).'" ' ; And it does not change the format but it insert into my databse 01-01-1970
@StanislasPiotrowski You forgot a "-" in date_facture= "'.date('Ym-d',strtotime($_POST['date_facture Ym should probably me Y-m-d?And if you format as Y-m-d H:i:s it will do that for all browsers.
Oh I did not notice that previously. Thank you verry much for your help. I thought it was a problem of comptatibility between all browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.