How to convert node.js date to SQL Server compatible datetime?
<p>I have a Web Api using <strong>express</strong> and <strong>Tedious</strong> to store some data on Azure SQL database. With <code>nvarchar</code> types and <code>int</code> types it works well, but when I try to save <code>DateTime</code> value I get an error message:</p>

<pre><code>Insert into Proxy (Ip, RequisitionDate) 
values ('1', '2016-05-18 3:32:21' )
</code></pre>

<p>Error:</p>

<blockquote>
  <p>RequestError: Validation failed for parameter 'RequisitionDate'. Invalid date.]
    message: 'Validation failed for parameter \'RequisitionDate\'. Invalid date.', code: 'EPARAM' }</p>
</blockquote>

<p>Well, the interesting thing is that </p>

<pre><code>Insert into Proxy (Ip, RequisitionDate) 
values ('1', '2016-05-18 3:32:21')
</code></pre>

<p>is the query that i execute in node.js api:</p>

<pre><code>var query = "Insert into Proxy (Ip,RequisitionDate) values ( '"+ ip + "', '"+ date + "' )";
console.log(query); // Insert into Proxy (Ip,RequisitionDate) values ( '1', '2016-05-18 3:32:21' )

request = new Request(query, function(err) {
    if (err) {
        console.log(err);}
    });

    request.addParameter('Ip', TYPES.NVarChar,'SQL Server Express 2014');
    request.addParameter('RequisitionDate', TYPES.DateTime , 'SQLEXPRESS2014');

    connection.execSql(request);
}
</code></pre>

<p>If I execute the query direct on the SqlManager Studio, it works ok.</p>