chamara chamara - 1 month ago 8
C# Question

Determine if DateTime is in a given Date Range

Aries March 21 to April 20.
Taurus April 21 to May 20.
Gemini May 21 to June 21.


I need to print the Astrological sign of a user by getting the user's birth month and the date as inputs. How can I get the date range?

EX: March 21 to April 20

Answer

You don't actually need to construct a datetime range to solve this. A simple switch statement based on the month with a simple if statement for each month that returns one of two star signs will suffice.

   e.g
     switch (month)
     {
       case 1:
          if (day <20) return "Capricorn"; else return "Aquarius";
          break;
       case 2:
          ...