Note that there are some explanatory texts on larger screens.

plurals
  1. PODateTime in entity Framework && DateTime in sql format returning different results
    text
    copied!<p>Guys i have a big problem in entity framework and DateTime. Here the problem:</p> <p>First with entity:</p> <p>When the user submit the form them those values are being create for a condicional query depending on which parameter the user type. Example:</p> <pre><code>var query = from user in UserTable select user; if(Request.Form["Category"]) { query = query.where(add=&gt;add.Category == Request.Form["Category"]) } //and here the between if(Request.Form["start_date"] &amp;&amp; Request.Form["end_date"]) { query = query.where(add=&gt;add.Date &lt; Request.Form["start_date"] &amp;&amp; add.Date &gt; Request.Form["end_date"] )//equivalent to between } until... return query.ToList(); </code></pre> <p>Good, but the problem remains that when the user wants to search by date, when converting the request form to datetime then the format are different from the input what was recived:</p> <pre><code>User'input 2003-12-02 Convert.ToDateTime result : 02/11/2003(not iqual to the user input) </code></pre> <p>So, there is not coincidence(Well, thats what i guest because I read that entity solved this by itself). And i cannot set Date propery to String Because i cannot use between with a string.</p> <p>Here the model simplified:</p> <pre><code>public string Category {get;set;} public DateTime Date{get;set;} </code></pre> <p>But Thats not all</p> <p><strong>Part 2</strong></p> <p>I tried to query in <code>02/11/2003</code> format to see if the query works and it did correctly, but when i tried with <code>2003-12-02</code>, here the results</p> <pre><code> 02/12/2003 format 16330 rows 2003-12-02 format 136 rows </code></pre> <p>Notice that they are the same but return different results. Moreover, when i check the results, i noticed that when querying in <code>02/12/2003 format</code> the results include date lesser or highter:</p> <p>Example:</p> <pre><code>Select date FROM Table WHERE date BETWEEN 02/12/2003 AND 03/12/2003 results include: 05/12/2003,30/12/2003 </code></pre> <p>Why this significant diffents bettwen those two queries?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload