title: Date and Time comparison including AM/PM in iphone sdk
body: <p>I need to compare two dates with time (am/pm). I used the following code.</p>
  
  <pre><code>-(NSDate*)dateFromString:(NSString*)dateString{
      // Convert string to date object
      NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
      [dateFormat setDateFormat:@"yyyy-MM-dd H:mm:ss"];
      NSDate *date = [dateFormat dateFromString:dateString];  
      [dateFormat release];
  
      return date;
  }
  
  #define kMinute 60
  #define kHour (60*60)
  #define kDay (60*60*24)
  -(NSString*)textFromSeconds:(double)seconds{
      if(seconds &lt; kMinute)
          return [NSString stringWithFormat:@"%0.0f seconds",seconds];
  
      if(seconds &lt; kHour)
          return [NSString stringWithFormat:@"%0.0f minutes",seconds/kMinute];
  
      if(seconds &lt; kDay)
          return [NSString stringWithFormat:@"%0.0f hours",seconds/kHour];
  
      return [NSString stringWithFormat:@"%0.0f days", seconds/kDay];
  }
  
  -(NSString*)textFromDateString:(NSString*)dateString{
      NSDate *date =[self dateFromString:dateString];
      double seconds = [[NSDate date] timeIntervalSinceDate:date];
      NSString *text = [self textFromSeconds:seconds];
      NSLog(@"text is: %@", text);
      return text;
  }
  
  -(void)test{
      [self textFromDateString:@"2011-02-20 17:19:25"];
      [self textFromDateString:@"2011-02-20 17:10:25"];
      [self textFromDateString:@"2011-02-20 14:04:25"];
      [self textFromDateString:@"2011-02-19 14:04:25"];
  }
  </code></pre>
  
  <p>Its working perfect. But I need to convert this into 12 hour clock. So that I need to compare two dates with AM or PM. What modifications should I do in the above code to achieve the goal?</p>
  
  <p>I changed the dateformat to @"yyyy-MM-dd HH:mm a" and tried with date in the same format, But its not working.</p>
  
  <p>Thanks.</p>