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 7519323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:53:01+00:00 2026-05-30T01:53:01+00:00

I am trying to compare two dates but I can t see how it

  • 0

I am trying to compare two dates but I can t see how it works at all …

this is the code that I am using :

   NSCalendar* myCalendar = [NSCalendar currentCalendar];
    NSDateComponents* components = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 

                                                 fromDate:[NSDate date]];
    [components setYear:2012];
    [components setMonth:03];
    [components setDay:25];
    NSDate *startDate = [myCalendar dateFromComponents:components];


    NSDateComponents* components2 = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 

                                                 fromDate:[NSDate date]];
    [components2 setYear:2012];
    [components2 setMonth:04];
    [components2 setDay:25];
    NSDate *endDate = [myCalendar dateFromComponents:components];

    NSComparisonResult result1 = [now compare:startDate];
    NSComparisonResult result2 = [now compare:endDate];

    if (result2 &&

        result1
        ) {
        int x =1;
    }

the thing is even if the two dates are in the future , i still can get into the if condition … any reason ?

  • 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-30T01:53:02+00:00Added an answer on May 30, 2026 at 1:53 am

    The values of result1 and result2 are one of the following.

    enum {
        NSOrderedAscending = -1,
        NSOrderedSame,
        NSOrderedDescending
    };
    typedef NSInteger NSComparisonResult;
    

    The only time (result2 && result1) wouldn’t return true is when one of them evaluates to false or 0. This only happens if one of the dates is exactly the same as now.

    if (result1 == NSOrderedAscending) {
        // result1 is in the future
    }
    
    if (result1 == NSOrderedDescending) {
        // result1 is in the past
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two dates. I have this code which I thought
I'm trying to compare two datetimes but I can't get it to work. public
I am trying to compare two Ruby Hashes using the following code: #!/usr/bin/env ruby
im trying to compare two dates like this ICriteria criteria = base.DataStore.TransactionScope.NHibernateSession.CreateCriteria<CcCorte>(); criteria.Add(Restrictions.Ge(Start, init.Date));
Trying to compare some dates in java but can't get the formatting right, where
I'm trying to compare two urls using PHP, ensuring that the domain name is
I am trying to compare two strings in Smalltalk, but I seem to be
I trying to compare two dates (DateTime) in nHibernate linq: query = query.Where(l =>
I am trying to get two dates from a SQL query, and compare them.
I am having a problem when i am trying to compare two dates in

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.