title: Set the first of the month of a NSDate
body: <p>I'm using a NSDate that is incremented/decremented thanks to NSDateCompoments:</p>
  
  <pre><code>dateComponents = [[NSDateComponents alloc] init];
      self.date = [gregorian dateByAddingComponents:dateComponents toDate:[NSDate date] options:0];
  </code></pre>
  
  <p>...</p>
  
  <pre><code>[dateComponents setDay:1];
                      self.date = [gregorian dateByAddingComponents:dateComponents toDate:self.date options:0];
                      [dateComponents setDay:0];
  </code></pre>
  
  <p>Now, I want to set the day to set the NSDate to the first of the month (and the first month of the year too), but I dont know how to do</p>
  
  <p>Thanks a lot!!!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code> NSDateComponents *dateComponentsSetFirst = [gregorian components:( NSYearCalendarUnit |
                                                                NSMonthCalendarUnit | NSDayCalendarUnit ) fromDate:self.date];
  
      switch (self.segmentedControl.selectedSegmentIndex) {
          case 0:
              requestTy = @"hours";
              break;
          case 1:
              requestTy = @"days";
              NSLog (@"avant %@",self.date);
              [dateComponents setDay:1];
              self.date = [gregorian dateFromComponents:dateComponentsSetFirst];
              [dateComponents setDay:0];
              NSLog (@"après %@",self.date);
              break;
          case 2:
              requestTy = @"months";
              NSLog (@"before %@",self.date);
              [dateComponents setMonth:1];
              self.date = [gregorian dateFromComponents:dateComponentsSetFirst];
              [dateComponents setMonth:0];
              NSLog (@"after : %@",self.date);
              break;
          default:
              break;
      }
  </code></pre>
  
  <p>give me </p>
  
  <pre><code>2011-08-17 11:23:34.365 e-mars[20942:207] avant 2011-08-17 09:23:30 GMT
  2011-08-17 11:23:34.366 e-mars[20942:207] après 2011-08-16 22:00:00 GMT
  </code></pre>
  
  <p>when I pass in the case 1 !</p>
  
  <p>and</p>
  
  <pre><code>2011-08-17 11:26:05.747 e-mars[20942:207] before 2011-08-16 22:00:00 GMT
  2011-08-17 11:26:05.747 e-mars[20942:207] after : 2011-08-16 22:00:00 GMT
  </code></pre>
  
  <p>when I pass in the case 2 !</p>