Q:

get value of query from jQuery date picker (format issue)

i have a table with events and want to list all events based on the date range the user will pick. I use jQuery datepicker, take value from it and put to sql query to show the events be†ween selected date range. My date format is YYYY-mm-dd (f.e 2016-05-05),but when I select the date from date picker it comes as (YYYY-05-05). For some reason it does not convert yyyy to date, but does for month and day. here is my code:
 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
 <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
 <link rel="stylesheet" href="/resources/demos/style.css">

 <script>
 $(function() {
 var firstdate = $('#firstdatepicker').datepicker({ dateFormat: 'YYYY- mm-dd' }).val();
 });
 </script>

 <script>
 $(function() {
 var lastdate = $('#lastdatepicker').datepicker({ dateFormat: 'YYYY-mm- dd' }).val();
 });
 </script>
</head>
<body>
<form method="post" action="archive.php">
  <p>First Date: <input name = "firstdatepicker" type="text"  id="firstdatepicker"></p>

 <p>Last Date: <input name = "lastdatepicker" type="text"  id="lastdatepicker"></p>

 <input type="submit" value="Get Data" name="data"/>

 </form>

And my query in php
 if(!isset($_POST['filters']) && isset($_POST['firstdatepicker']) && isset($_POST['lastdatepicker']) ){

 $firstdate = $_POST['firstdatepicker'];
 $lastdate = $_POST['lastdatepicker'];

$query= "SELECT *
        FROM Event
        WHERE Event.`start_date` BETWEEN '$firstdate' and '$lastdate'
        ORDER BY start_date DESC";

}

A:

Change to:
var lastdate = $('#lastdatepicker').datepicker({ dateFormat: 'yy-mm-dd' }).val();

and
var firstdate = $('#firstdatepicker').datepicker({ dateFormat: 'yy-mm-dd' }).val();

Have a look at: http://api.jqueryui.com/datepicker/#option-dateFormat

