title: Using BETWEEN Clause in NodeJS
body: <p>I want to fetch data using <strong>BETWEEN</strong> clause from MySql database.</p>
  
  <p>In client side, I created 2 inline calender with JQuery and emit selected <strong>date</strong> value with socket.io;</p>
  
  <pre><code>$('#fromDate').datepicker({
      inline: true,
      altField: '#d',
      dateFormat: "dd-mm-yy",
      altFormat: "yy-mm-dd",
      monthNames: ["Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"],
      dayNamesMin: ["Pa", "Pt", "Sl", "Ça", "Pe", "Cu", "Ct"],
      firstDay: 1,
      numberOfMonths: 1,
      onSelect: function(dateText, inst) {
        var dateAsString = dateText; //the first parameter of this function
        var dateAsObject = $(this).datepicker('getDate'); //the getDate method
        console.log(dateAsString);
        socket.emit('socketfromDate', $('#d').val());
      }
    });
  
    $('#toDate').datepicker({
      inline: true,
      altField: '#x',
      dateFormat: "dd-mm-yy", 
      altFormat: "yy-mm-dd", 
      monthNames: ["Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"],
      dayNamesMin: ["Pa", "Pt", "Sl", "Ça", "Pe", "Cu", "Ct"],
      firstDay: 1,
      numberOfMonths: 1,
      onSelect: function(dateText, inst) {
        var dateAsString = dateText; //the first parameter of this function
        var dateAsObject = $(this).datepicker('getDate'); //the getDate method
        console.log(dateAsString);
        socket.emit('sockettoDate', $('#x').val());
      }
    });
  </code></pre>
  
  <p>In server side, If I receive '<strong>toDate</strong>' value after '<strong>fromDate</strong>' value, MySql query must fetch data between these days. </p>
  
  <pre><code> var  fromDate_query,
        toDate_query;
  
  io.on('connection', function(socket) {
  
        socket.on('socketfromDate', function(fromDate) {
          console.log();
          console.log("----------------------------------");
          console.log("Selected dateTime 'from': " + fromDate); //output: Selected dateTime 'from': 2017-07-01 
          console.log("----------------------------------");
          console.log();
          fromDate_query = fromDate;
        });
  
        socket.on('sockettoDate', function(toDate) {
          console.log();
          console.log("----------------------------------");
          console.log("Selected dateTime 'to': " + toDate); //output: Selected dateTime 'to': 2017-07-13
          console.log("----------------------------------");
          console.log();
          toDate_query = toDate;
  
          connection.query("SELECT * FROM report WHERE date BETWEEN ? AND  ?", [fromDate_query, toDate_query], function(err, rows) {
            if (err) console.log(err);
            else {
              for (var i = 0; i &lt; rows.length; i++) {
                var row = rows[i];
                console.log("**********************************");
                console.log("Possible machine: " + row.machine); //output: nothing
                console.log("**********************************");
              }
            }
          });
        });
      });
  </code></pre>
  
  <p>Problem is, nothing happens. </p>
  
  <p><em>What is the best approach for querying between two days?</em></p>