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

  • Home
  • SEARCH
  • 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 6030077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:58:59+00:00 2026-05-23T04:58:59+00:00

Possible Duplicates: Comparing dates How to compare two dates in Objective-C i want to

  • 0

Possible Duplicates:
Comparing dates
How to compare two dates in Objective-C

i want to compare 2 strings who have a date format “11-06-2011” and “12-06-2011” for exemple.
i want to see if the second date is greater than the first or not
can you help me please ?


i tried this code

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd-MM-YYYY"];
    NSDate *date1 = [dateFormat dateFromString:deparatureDateField.text];
    NSDate *date2 = [dateFormat dateFromString:comebackDateField.text];
    [dateFormat release];
    NSTimeInterval timeInterval = [date1 timeIntervalSinceDate:date2];
    if(timeInterval >= 0)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Attention" message:@"come back date should be greater" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
        [alert show];
    }

but i alwayse have an alert, NSTimeInterval timeInterval is alwayse NULL

  • 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-23T04:59:00+00:00Added an answer on May 23, 2026 at 4:59 am

    To find out if one date is larger than the other you’d have to do this:

    NSString *string1 = @"11-06-2011";
    NSString *string2 = @"12-06-2011";
    
    // Convert string to date object
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd-MM-yyyy"];
    NSDate *date1 = [dateFormat dateFromString:string1];
    NSDate *date2 = [dateFormat dateFromString:string2];
    [dateFormat release];
    
    NSComparisonResult comparisonResult = [date1 compare:date2];
    
    /*
    NSComparisonResult can be either of these values:
     - NSOrderedAscending (-1) //if date1 < date2
     - NSOrderedSame (0)       //if date1 = date2
     - NSOrderedDescending (1) //if date1 > date2
    */
    

    Alternatively (to compare:) you could use timeIntervalSinceDate: to get the actual time difference:

    NSTimeInterval timeInterval = [date1 timeIntervalSinceDate:date2];
    //timeInterval will be
    // - nagative if ascending,
    // - zero if same,
    // - positive if descending
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: Strange problem comparing floats in objective-C Is JavaScript’s math broken? 1.265 *
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: comparing contents of two files using python I have a file name
Possible Duplicate: Comparing object properties in c# Let's say I have a POCO: public
Possible Duplicate: How to find number of days between two dates using php I'm
Possible Duplicate: Comparing two arrays & get the values which are not common I
Possible Duplicates: Finding duplicate files and removing them. In Python, is there a concise
Possible Duplicates: String comparison and String interning in Java What is the difference between
Possible Duplicates: How can I convert ereg expressions to preg in PHP? What is
Possible Duplicates: How to split a string in C++? Splitting a C++ std::string using

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.