Note that there are some explanatory texts on larger screens.

plurals
  1. POLoad users by birthday
    primarykey
    data
    text
    <p>I want to know is there a better/easier way to load users by birthday.</p> <p>I have a User instance, which has properties, including this one: </p> <p><code>public DateTime? BirthDate { get; set; }</code></p> <p>What I want to do is to load that users who has bdays from one date to another:</p> <pre><code>public IEnumerable&lt;User&gt; LoadUsersByBirthday(DateTime from, DateTime into) </code></pre> <p>I don't care about birthday year, for example, if I have 3 users with birthdays:</p> <ol> <li>DateTime(1991, 3, 20); </li> <li>DateTime(1990, 4, 25);</li> <li>DateTime(1989, 3, 10);</li> </ol> <p><code>LoadUsersByBirthday(new DateTime(2990, 3, 1), new DateTime(3013, 4, 15))</code> should return 2 users - 1st and 3rd.</p> <p>My method looks like this:</p> <pre><code>public IEnumerable&lt;User&gt; LoadUsersByBirthday(DateTime from, DateTime into) { var days = DateTime.DaysInMonth(from.Year, from.Month); var u1 = _unit.User.Load(u =&gt; ((DateTime) (u.BirthDate)).Month == from.Month &amp;&amp; ((DateTime) (u.BirthDate)).Day &gt;= from.Day &amp;&amp; ((DateTime) (u.BirthDate)).Day &lt;= days); var u2 = _unit.User.Load(u =&gt; ((DateTime) (u.BirthDate)).Month &gt; from.Month &amp;&amp; ((DateTime) (u.BirthDate)).Month &lt; into.Month); var u3 = _unit.User.Load(u =&gt; ((DateTime) (u.BirthDate)).Month == into.Month &amp;&amp; ((DateTime) (u.BirthDate)).Day &lt;= into.Day); return u1.Concat(u2).Concat(u3); } </code></pre> <p>It works, but is there a better/easier way to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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