<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Query for DatePart</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Query for DatePart</description>
  <pubDate>Thu, 11 Jun 2026 00:08:38 -700</pubDate>
  <lastBuildDate>Tue, 22 Jul 2008 13:27:43 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=894</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Query for DatePart : thanks for the suggestion. the...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3242#3242</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=300" rel="nofollow">pucsoftware</a><br /><strong>Subject:</strong> 894<br /><strong>Posted:</strong> 22-Jul-2008 at 1:27pm<br /><br />thanks for the suggestion. the idea of using a view and relating it back to the employees brings up a lot of options I hadn't thought about. Thanks a lot. I'll give this a try.<DIV>&nbsp;</DIV><DIV>Darren</DIV>]]>
   </description>
   <pubDate>Tue, 22 Jul 2008 13:27:43 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3242#3242</guid>
  </item> 
  <item>
   <title>Query for DatePart : ah, yes, you did in fact say &amp;#034;a...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3241#3241</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=34" rel="nofollow">jeffdoolittle</a><br /><strong>Subject:</strong> 894<br /><strong>Posted:</strong> 22-Jul-2008 at 12:09pm<br /><br />ah, yes, you did in fact say "a birthday in the current month."&nbsp; I should have read more carefully.<br><br>Since EntityQueries cannot work with derived properties, these are your options:<br><br>1) create a passthrough query<br>2) create a view that does the Month(), Day(), Year() calculations.&nbsp; Something like this:<br><br>&nbsp;&nbsp;&nbsp; CREATE VIEW viwEmployeeDOB<br>&nbsp;&nbsp;&nbsp; AS<br>&nbsp;&nbsp;&nbsp; SELECT e.EmployeeId, Month(e.DateOfBirth) AS Month, Day(e.DateOfBirth) AS Day, Year(e.DateOfBirth) AS Year<br>&nbsp;&nbsp;&nbsp; FROM Employee e<br>&nbsp;&nbsp; <br>and then map this as a one-to-one related entity of the Employee entity.&nbsp; then you could do a sub query against this related entity's values.<br><br>3) create a stored procedure that returns employee objects <br>4) create a stored procedure or dynamic entity query that returns employee ids and then create an entity query that uses the "In" operator to retrieve the employees with matching id values<br><br>These options have will side-effects if you have changed DOB in the employee object but haven't persisted yet.&nbsp; Checking the database value when a local save hasn't persisted may result in unexpected behavior, so you'll need to be prepared to handle this situation.<br><br>5) if you don't have a lot of employees, or if there is some other way you can limit the number of results, you could just load all the employees into memory and use a foreach loop (or LINQ).&nbsp; Of course this won't scale well unless you have another way to limit the results.<br><br><br><br><br>]]>
   </description>
   <pubDate>Tue, 22 Jul 2008 12:09:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3241#3241</guid>
  </item> 
  <item>
   <title>Query for DatePart : Thanks for the suggestoin. I had...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3240#3240</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=300" rel="nofollow">pucsoftware</a><br /><strong>Subject:</strong> 894<br /><strong>Posted:</strong> 22-Jul-2008 at 10:37am<br /><br /><P>Thanks for the suggestoin. I had thought about this, too. But I really can't use a date field because I'm looking for who has a birthday this month of this year. If&nbsp;I use a date field, which includes the year, then I am looking for anyone who was&nbsp;BORN in the current month and year. We wouldn't have any employees that ever met that critieria. :)</P><DIV>It looks like I will have to use a passthrough query object. Unless there is some way to have the OQL language parse out a date field by using MONTH(), DAY(), or YEAR() functions then this isn't going to work with IEntityObjects. Bummer.</DIV><DIV>&nbsp;</DIV><DIV>Darren</DIV>]]>
   </description>
   <pubDate>Tue, 22 Jul 2008 10:37:40 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3240#3240</guid>
  </item> 
  <item>
   <title>Query for DatePart : I&amp;#039;m fairly certain that this...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3239#3239</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=34" rel="nofollow">jeffdoolittle</a><br /><strong>Subject:</strong> 894<br /><strong>Posted:</strong> 22-Jul-2008 at 9:38am<br /><br />I'm fairly certain that this will not work.&nbsp; The "StartsWith" operator works with strings, but I'm assuming your "DOB" property is a DateTime.<br><br>How about this approach?<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static EntityQuery GetByBirthMonthQuery(int month, int year) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EntityQuery empQuery = new EntityQuery(typeof(Employee));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DateTime startDate = new DateTime(year, month, 1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DateTime endDate = startDate.AddMonths(1).AddTicks(-1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; empQuery.AddClause(Employee.DateOfBirthEntityColumn, EntityQueryOp.Between, startDate, endDate);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return empQuery;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br><br>]]>
   </description>
   <pubDate>Tue, 22 Jul 2008 09:38:43 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3239#3239</guid>
  </item> 
  <item>
   <title>Query for DatePart : I need to create a query looking...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3238#3238</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=300" rel="nofollow">pucsoftware</a><br /><strong>Subject:</strong> 894<br /><strong>Posted:</strong> 22-Jul-2008 at 8:19am<br /><br />I need to create a query looking for all the employees who have a birthday in the current month. I have a column that represents the birthdate of an employee. How do I find all the employees with a birthdate in a current month? Since this is a date field in SQL I would use the DatePart function. I could also use this same strategy for getting all the records in a year or on a specific day. From what I've read about creating queries I could do something similar to this:<DIV>&nbsp;</DIV><FONT size=2><P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>public</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>static</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>RdbQuery</FONT></FONT><FONT size=2> GetEmpoyeeDobByMonth(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>string</FONT></FONT><FONT size=2> sMonth) { </P><P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>RdbQuery</FONT></FONT><FONT size=2> query = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>RdbQuery</FONT></FONT><FONT size=2>(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>typeof</FONT></FONT><FONT size=2>(</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Employee</FONT></FONT><FONT size=2>)); </P><DIV></FONT><FONT size=2>query.AddClause(</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Employee</FONT></FONT><FONT size=2>.DOBEntityColumn, </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>EntityQueryOp</FONT></FONT><FONT size=2>.StartsWith, sMonth);</DIV><P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> query; </P><P>} </P><DIV></DIV><P>Even if this would work for finding the month, it&nbsp;doesn't address how I could get the day or year. Where can I get more info on working with date columns in the OQL language?</P><DIV></DIV>Darren</FONT>]]>
   </description>
   <pubDate>Tue, 22 Jul 2008 08:19:10 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=894&amp;PID=3238#3238</guid>
  </item> 
 </channel>
</rss>