title: Getting Start & End of Month for 12 Months (A Year)
body: <p>I'm actually creating a method to get details for my asp Chart based on a certain datetime range. I've looked at these 2 links,</p>
  
  <p><a href="https://stackoverflow.com/questions/2821035/c-sharp-get-start-date-and-last-date-based-on-current-date">First Link</a> , 
  <a href="https://stackoverflow.com/questions/24245523/getting-the-first-and-last-day-of-a-month-using-a-given-datetime-object">Second Link</a></p>
  
  <p>My method to retrieve data,</p>
  
  <pre><code>//Monthly Statistics
  public int janLogin(String username)
  {
      int result = 0;
  
      StringBuilder sqlCmd = new StringBuilder();
      sqlCmd.AppendLine("SELECT COUNT(*) FROM AuditActivity WHERE Username = @getUsername AND DateTimeActivity BETWEEN @getFirstDT AND @getLastDT AND ActivityType = @getType");
  
      try
      {
          SqlConnection myConn = new SqlConnection(DBConnectionStr);
  
          myConn.Open();
  
          SqlCommand cmd = new SqlCommand(sqlCmd.ToString(), myConn);
  
          //DateTime
          DateTime currentDT = DateTime.Today;
  
          //Code Below gets only current Start and End of Current month
          DateTime FirstDT = currentDT.AddDays(1 - currentDT.Day);
          DateTime SecondDT = FirstDT.AddMonths(1).AddSeconds(-1);
  
          cmd.Parameters.AddWithValue("@getUsername", username);
          cmd.Parameters.AddWithValue("@getFirstDT", FirstDT);
          cmd.Parameters.AddWithValue("@getLastDT", SecondDT);
          cmd.Parameters.AddWithValue("@getType", "Login");
  
          result = Convert.ToInt16(cmd.ExecuteScalar());
  
          myConn.Close();
  
          return result;
      }
      catch (SqlException ex)
      {
          logManager log = new logManager();
          log.addLog("AuditNLoggingDAO.janLogin", sqlCmd.ToString(), ex);
          return 0;
      }
  }
  </code></pre>
  
  <p>What i'm trying to actually do as you can see from the method name janLogin basically to get how many people logged in from <strong>1 Jan 2017 00:00:00 to 31 JAN 2017</strong>. Current month is actually August. How can i actually get for all twelve months (Jan to Dec) the start and end month (from the bold example) for current year of 2017?</p>
  
  <p>If i'm not wrong it's having to involve a for loop? Where the end count is 12. But i'm quite sure on how to do it.. There might be a duplicated question but i cant seem to find one that fits my requirement..</p>
  
  <p>Appreciate any help. Thank you!</p>