title: DATEDIFF how to write in Asp.net MVC
body: <p>I am creating a car retail system. I need to the display if I enter the correct <code>carid</code> relevant car information will be displayed in the below text boxes. I have attached the screen shot image below. I need to calculate day difference between start date and end date for calculation of how many days between because  retail fee needs to be calculated for extra days of the retail system. In C# i wrote like this <code>select car_id,cust_id,due,DATEDIFF(GETDATE(),due) as elap from rental where car_id = ?</code>
  I don't know how to write in Asp.net MVC. </p>
  
  <p>Code I tried:</p>
  
  <p><strong>form design</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;div class="col-sm-8"&gt;
  
          @using (Html.BeginForm("Save", "return", FormMethod.Post, new { id = "popupForm" }))
          {
              &lt;div&gt;
                  &lt;h4&gt; Registation&lt;/h4&gt;
              &lt;/div&gt;
  
                &lt;div class="card-action"&gt;
  
                  &lt;label class="form-label"&gt;Car ID&lt;/label&gt;
                    &lt;input type="text" id="carno" name="carno" class="form-control" placeholder="carno" required /&gt;
              &lt;/div&gt;
  
  
  
              &lt;div class="card-action"&gt;
  
                  &lt;label class="form-label"&gt;Customer ID&lt;/label&gt;
  
                  &lt;input type="text" id="custid" name="custid" class="form-control" placeholder="Customer ID" required /&gt;
  
              &lt;/div&gt;
  
  
  
              &lt;div class="card-action"&gt;
  
                  &lt;label class="form-label"&gt;Date&lt;/label&gt;
  
                  &lt;input type="text" id="date" name="date" class="form-control" placeholder="Date" required /&gt;
  
              &lt;/div&gt;
  
  
               &lt;div class="card-action"&gt;
  
                  &lt;label class="form-label"&gt;Days Elapsed&lt;/label&gt;
  
                   &lt;input type="text" id="elap" name="elap" class="form-control" placeholder="Date" required /&gt;
  
              &lt;/div&gt;
  
  
               &lt;div class="card-action"&gt;
  
                  &lt;label class="form-label"&gt;Fine&lt;/label&gt;
  
                   &lt;input type="text" id="fine" name="fine" class="form-control" placeholder="Fine" required /&gt;
  
              &lt;/div&gt;
  
  
              &lt;div class="card"&gt;
                  &lt;input type="submit" value="Save" class="btn btn-default" /&gt;
              &lt;/div&gt;
  
          }
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>jQuery seach the data using jquery</strong></p>
  
  <pre><code>   &lt;script&gt;
          getProductcode();
          function getProductcode() {
              $("#carno").empty();
              $("#carno").keyup(function (e)
              {
                  var q = $("#carno").val();
                  $.ajax({
                      type: "POST",
                      url: '/return/Getid?carno=' + $("#carno").val(),
                      dataType: "JSON",
                      success: function (data)
                      {
                          console.log(data);
                            $('#custid').val(data.custid);
                            $('#date').val(data.sdate);
                             $('#elap').val(data.elap);
  
                      },
                      error: function (xhr, status, error)
                      {
                          //  alert("The barcode entered is not correct");
                      }
                  });
                  return true;
              });
          }
  
      &lt;/script&gt;
  </code></pre>
  
  <p><strong>returnController</strong></p>
  
  <pre><code> [HttpPost]
          public ActionResult Getid(String carno)
          {
              carrentEntities1 db = new carrentEntities1();
              var carn = (from s in db.rentails where s.carno == carno select s.custid).ToList();
              return Json(carn, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <p>I don't know how to write the Datediff to calculate days. In this no result displayed. I tested <code>custid</code>, it didn't display.</p>
  
  <p><strong>Database fields</strong></p>
  
  <pre><code>id  carno   custid  fee   sdate      edate
  1   1        1     1200  2019-12-09  2019-12-19
  2   1        1     20000 2019-12-01  2019-12-31
  3   A0001    1     3434  2019-12-09  2019-12-27
  </code></pre>