Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:32:35+00:00 2026-05-27T22:32:35+00:00

i am trying to compare the date but its not comparing the date like

  • 0

i am trying to compare the date but its not comparing the date like 31-dec-2011 with 1-01-2012. i was trying to remove values at 31-dec-2011 and any other values previous then 1-01-2012. here i am doing this: i want to show the values at today’s date and on upcoming dates.

-(void)showcurrentdate
{
    NSDate *objdate=[NSDate date];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"dd-MM-YYYY"];

NSDate *str1= (NSDate *)[dateformatter stringFromDate:objdate];

NSLog(@"configuregameArray......%d",[configuregameArray count]);

if([configuregameArray count]>=1)
{    
  NSMutableArray* indexarray= [[NSMutableArray alloc]init];  
  for(int k =0; k<[configuregameArray count]; k++)
 {

    NSDate *datefromarray = (NSDate *)[[configuregameArray objectAtIndex:k] objectForKey:@"gd"];  

     NSComparisonResult result = [datefromarray compare:str1];

     switch (result)
     {               

         case NSOrderedAscending:

             NSLog(@"%@ is greater from %@", str1 ,datefromarray);
             indexNumber = [NSString stringWithFormat:@"%d",k];
             [indexarray addObject:indexNumber];
             NSLog(@"indexarray......%@",indexarray);
             break;


         default: 
             NSLog(@"going fine");   
                            break;
     }

 }


    NSMutableIndexSet *discardedItems = [NSMutableIndexSet indexSet];
    for(int i=0; i<[indexarray count]; i++)
    {
       NSInteger removeindex = [[indexarray objectAtIndex:i]intValue];        
       [discardedItems addIndex:removeindex];

     }

    [configuregameArray removeObjectsAtIndexes:discardedItems];
}
NSLog(@"configuregameArray......%@",configuregameArray);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:32:36+00:00Added an answer on May 27, 2026 at 10:32 pm

    Given that you have your dates stored as strings in another array and that you want to end up with an array of strings, filtering out only the dates that occur after a certain date would take these steps:

    • Get the date to filter with
    • Loop over all strings
      • Use a date formatter to convert the string to a date object.
      • Compare the converted date to the filter date
        • Store the index of the date string if the converted date occurs after the filter date
    • Create a new array of strings with the indexes you stored while looping all strings.

    Obviously it would be better to store dates in the array. This make all date calculations much easier. Then you could filter the array with a one line NSPredicate instead of many lines of code. It is generally a bad design to store objects as strings. A much better practice is to store the objects as objects and convert them to strings when presenting them in a user interface. This was you can change how the objects are formatted without having to change how they are stored, converted, and used. It is a separation of concerns where the interface who is concerned about showing dates as strings converts dates to strings while the model who is concerned about dates uses dates and doesn’t care about strings at all.

    Anyhow, code for the above steps to filter the date strings in your question would look something like below. If you want to filter using todays date you can use [NSDate date]; to get todays date as a date and not a string.

        // Create some sample date strings 
        NSArray *dateStrings = [NSArray arrayWithObjects:@"01-01-2012", @"03-01-2012", @"01-03-2012", @"10-08-2011", @"06-02-2002", @"20-04-1999", @"01-01-2012", @"31-12-2011", @"07-03-2014", @"18-09-3456", @"27-07-1924", nil];
    
        // The same kind date format as the question
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        dateFormatter.dateFormat = @"dd-MM-YYYY";
    
        // The date that other dates are filtered using
        NSDate *filterDate = [dateFormatter dateFromString:@"01-01-2012"];
    
        ///////////// OUTPUT /////////////
        NSLog(@"BEFORE: %@", dateStrings);
        //////////////////////////////////
    
        // Get the indexes of all dates after the filterDate.
        NSIndexSet *newerDateIndexes = [dateStrings indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
            NSString *dateString = (NSString *)obj; // The string stored in the array
            NSDate *date = [dateFormatter dateFromString:dateString]; // Use the dateFormatter to get a date from the array
    
            // Add this index to the index set if the date occurs after the filterDate.
            return ([date compare:filterDate] != NSOrderedAscending);
        }];
    
        // A new array with only the dates after the filterDate
        NSArray *filteredDateString = [dateStrings objectsAtIndexes:newerDateIndexes];
    
        ///////////// OUTPUT ///////////////////
        NSLog(@"AFTER: %@", filteredDateString);
        ////////////////////////////////////////
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compare just the date of a column but because the query
I'm pretty new to the jquery validation plugin. Trying to compare date values in
Im trying to compare these two chars but on win 32 Visual Studio 2008:
I am trying to compare two decimal values in Java script. I have two
I am trying to compare two strings in Smalltalk, but I seem to be
I have problems comparing the datetime property of objects and when trying to compare
I am trying to compare two dates but I can t see how it
i was trying to compare the difference between 2 dates, but it seems the
I am trying to compare two dates which are in Finnish time form like
Trying to compare some dates in java but can't get the formatting right, where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.