title: Can't insert datepicker date into mysql
body: <p>I'm having problems formatting a date from a datepicker to insert it in to a mysql database. As you can see the datepicker format is <strong>yy-mm-dd</strong> and i need simple <strong>Y-m-d</strong> mysql format. I have tried many options, like replacing a string "\" to "-" and strtotime() and both together, but it just doesn't work. Can you help me please?</p>
  
  <p>My code is:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;script&gt;
    $(document).ready(function() {
      $("#datepicker").datepicker({
          dateFormat: 'yy-mm-dd'
      });
    });
    &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="wrap"&gt; &lt;!--wrap start--&gt;
          &lt;br /&gt;
          &lt;h1&gt;Zbiranje podatkov&lt;/h1&gt;
           &lt;form action="" method="post" id="mainform"&gt;
          &lt;table id="table_data"&gt;
  
              &lt;tr&gt; 
                  &lt;td&gt;Ime&lt;/td&gt;
                  &lt;td&gt;&lt;input name="fname" type="text" size="40"&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;span class="fname_val validation"&gt;&lt;/span&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt; 
                  &lt;td&gt;Priimek&lt;/td&gt;
                  &lt;td&gt;&lt;input name="lname" type="text" size="40"&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;span class="lname_val validation"&gt;&lt;/span&gt;&lt;/td&gt;
  
              &lt;/tr&gt;
              &lt;tr&gt; 
                  &lt;td&gt;E-pošta&lt;/td&gt;
                  &lt;td&gt;&lt;input name="email" type="text" size="40"&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;span class="email_val validation"&gt;&lt;/span&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt; 
                  &lt;td&gt;Datum&lt;/td&gt;
                  &lt;td&gt;&lt;input id="datepicker" size="40" name="datepicker" type="text" /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;span class="datepicker_val validation"&gt;&lt;/span&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&lt;input name="register" type="button" value="Potrdi"&gt; &lt;span class="loading"&gt;&lt;/span&gt;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;div id="note"&gt;
          &lt;b&gt;Email Already Exist:&lt;/b&gt; &lt;span style="color:#B41F2B;"&gt;john_doe@istockphp.com&lt;/span&gt;
          &lt;/div&gt;
         &lt;/form&gt;
       &lt;/div&gt; &lt;!--wrap end--&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And PHP IS:</p>
  
  <pre><code>&lt;?php
  require_once("database.php"); //
  header('Content-Type: text/html; charset=utf-8');
  
  /* catch the post data from ajax */
  $fname = $_POST['fname']; 
  $lname = $_POST['lname'];
  $email = $_POST['email'];
  $date = date('Y-m-d',  strtotime($_POST['datepicker']));
  
  $query = mysql_query("SELECT `email` FROM `contacts` WHERE `email` = '$email'");
  if(mysql_num_rows($query) == 1) { // if return 1, email exist.
      echo '1';
  } else { // else not, insert to the table
  
      $query = mysql_query("INSERT INTO `contacts` (`name` ,`surname` , `email`, `birthday`, `insert_timestamp`)
                          VALUES ('$fname', '$lname', '$email', '$date', NOW())"); 
  
    }
  
  ?&gt;
  </code></pre>
  
  <p>JS code is here:</p>
  
  <pre><code>jQuery(function($) {
      var val_holder;
  
      $("form input[name='register']").click(function() { // triggred click 
  
          /************** form validation **************/
          val_holder      = 0;
          var fname       = jQuery.trim($("form input[name='fname']").val()); // first name field
          var lname       = jQuery.trim($("form input[name='lname']").val()); // last name field
          var email       = jQuery.trim($("form input[name='email']").val()); // email field
                  var datepicker      = jQuery.trim($("form input[name='datepicker']").val()); // datum field
          var email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; // reg ex email check  
  
          if(fname == "") {
              $("span.fname_val").html("Prosimo vpišite ime.");
          val_holder = 1;
          } 
          if(lname == "") {
              $("span.lname_val").html("Prosimo, vpišite priimek.");
          val_holder = 1;
          } 
          if(email == "") {
              $("span.email_val").html("Prosimo, vpišite emial.");
          val_holder = 1;
          }
                  if(datepicker == "") {
              $("span.datepicker_val").html("Prosimo, izberite datum.");
          val_holder = 1;
          }
          if(email != "") {
              if(!email_regex.test(email)){ // if invalid email
                  $("span.email_val").html("Email ni pravilen.");
                  val_holder = 1;
              } 
          }
          if(val_holder == 1) {
              return false;
          }  
          val_holder = 0;
          /************** form validation end **************/
  
          /************** start: email exist function and etc. **************/
          $("span.loading").html("&lt;img src='images/ajax_fb_loader.gif'&gt;");
          $("span.validation").html("");
  
          var datastring = 'fname='+ fname +'&amp;lname='+ lname +'&amp;email='+ email; // get data in the form manual
          //var datastring = $('form#mainform').serialize(); // or use serialize
  
          $.ajax({
                      type: "POST", // type
                      url: "check_email.php", // request file the 'check_email.php'
                      data: datastring, // post the data
                      success: function(responseText) { // get the response
                          if(responseText == 1) { // if the response is 1
                              $("span.email_val").html("&lt;img src='images/invalid.png'&gt; E-poštni naslov že obstaja.");
                              $("span.loading").html("");
                          } else { // else blank response
                              if(responseText == "") { 
                                  $("span.loading").html("&lt;img src='images/correct.png'&gt; Registracije je uspešna.");
                                  $("span.validation").html("");
                                  $("form input[type='text']").val(''); // optional: empty the field after registration
                              }
                          }
                      } // end success
          }); // ajax end
          /************** end: email exist function and etc. **************/
      }); // click end
  }); // jquery end
  </code></pre>