I have been searching for quite a while now and I can't figure out why my query isn't working for dates.
I want it to be imported to my database as a Date, this is a choice from higher up so here I am.
$insert_query = "INSERT INTO enrties(
`datum` )
VALUES (
'".mysql_real_escape_string($_SESSION['Datum'])."')
a few pages before the above i use this piece of code to fill the $_SESSION
$DateDag = $_POST['Dag'];
$DateMaand = $_POST['Maand'];
$DateJaar = $_POST['Jaar'];
switch ($dateMaand)
{
case 'Januari': $DateMaand = '01'; break;
case 'Februari': $DateMaand = '02'; break;
case 'Maart': $DateMaand = '03'; break;
case 'April': $DateMaand = '04'; break;
case 'Mei': $DateMaand = '05'; break;
case 'Juni': $DateMaand = '06'; break;
case 'July': $DateMaand = '07'; break;
case 'Augustus': $DateMaand = '08'; break;
case 'September': $DateMaand = '09'; break;
case 'Oktober': $DateMaand = '10'; break;
case 'November': $DateMaand = '11'; break;
case 'December': $DateMaand = '12'; break;
}
$_SESSION['Datum'] = $DateDag. '-'. $DateMaand. '-'. $DateJaar;
I want to have the date imported as a SQL Date format (preferably DD-MM-YYYY format).
SOLVED, there was a mistake in the switch Apparantly, not really sure what but it works ;)
after date is inserted you can format after query
$new_format=date('h:i:s d/m/Y',strtotime($date_string));
The MySQL date format is actually YYYY-MM-DD, so if you want to insert a date (guessing your datum field is Date or Datetime) you have to set up your string in that way.
If you want to insert your date in a different way you should use this:
but this will save always the date in YYYY-MM-DD way, since is the default for mysql.
MySQL date format has to be YYYY-MM-DD
Turn it around so it looks like: