title: Time difference between current time and cookie expiation time in asp c#
body: <p>Here is the code I used to check the time difference between cookie expiration time and current time. </p>
  
  <pre><code>HttpCookie mycookie = Request.Cookies.Get("hello");
  
  if (mycookie == null)
  {
      mycookie = new HttpCookie("hello");
      mycookie.Value = "Hello World";
      mycookie.Expires = DateTime.Now.AddMinutes(20);
      Response.Cookies.Add(mycookie);
  
      DateTime now = DateTime.Now;
      Response.Write("Cookie Not found &lt;br&gt; Time diff : ");
      Response.Write((mycookie.Expires - now).TotalMinutes);
  }
  else
  {
      DateTime now = DateTime.Now;
      Response.Write("Cookie found &lt;br&gt; Time diff : ");
      Response.Write((mycookie.Expires - now).TotalMinutes);
  }
  </code></pre>
  
  <p>As you can see, I'm checking whether a cookie exists or not. If does not exist then I create a cookie and print time difference, this works fine and print <code>20</code> as expected(when I run this for the first time). If cookie exists, I print the time difference without creating cookie, this is not working(when I run this for second time or page refresh), this prints some negative long number.</p>