Pass date from javascript via php to mysql
<p>I have a Date in this form in JavaScript: "10.02.2010".</p>

<p>I Pass it via url to php, together with other variables.</p>

<p>Then I convert it in php to a php-Date like this:</p>

<pre><code>foreach ($_GET as $key =&gt; $value) {
    if ($key == "TPopMassnDatum") {
        if ($value) {
            $value = date("Y-m-d H:i:s", strtotime($value));
        } else {
            $value = null;
        }
    } 
}
</code></pre>

<p>I've also tried this:</p>

<pre><code>$value = date_create_from_format('d.m.Y', $value);
</code></pre>

<p>Because there are several other values and I need to insert, I implode the keys:</p>

<pre><code>$Feldliste = implode(",", array_keys($_GET));
</code></pre>

<p>then implode the values:</p>

<pre><code>$Wertliste = '"'.implode('","', array_values($_GET)).'"';
</code></pre>

<p>then run this query:</p>

<pre><code>$Querystring = 'INSERT INTO tblTeilPopMassnahme ('.$Feldliste.') VALUES ('.$Wertliste.')';
</code></pre>

<p>The date field in mysql is datetime.</p>

<p>My problem: The dates, as they arrive in mysql, are usually off. For example: 20.04.2006 instead of 20.12.2012.</p>

<p>What am I doing wrong?</p>
