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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:17:27+00:00 2026-05-18T09:17:27+00:00

I want to sort an array of NSDates only on their day month and

  • 0

I want to sort an array of NSDates only on their day month and year so not on any of the units of time. How can I do this because I can’t see a way of getting the individual parts of an NsDate “out”.

  • 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-18T09:17:28+00:00Added an answer on May 18, 2026 at 9:17 am

    See this post for sorting an array containing NSDate objects:

    Sort NSArray of date strings or objects

    and mine for removing the time:

    Truncate NSDate (Zero-out time)

    ADDITION

    1) Loop through your array of NSDate objects, removing (zeroing) the time components, and adding them to a new array:

    NSMutableArray *newDateArray = [NSMutableArray array];
    for (NSDate *d in myDateArray)
    {
        unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
        NSCalendar* calendar = [NSCalendar currentCalendar];
        NSDateComponents* components = [calendar components:flags fromDate:d];
        //Taking the time zone into account
        NSDate *dateOnly = [[calendar dateFromComponents:components] dateByAddingTimeInterval:[[NSTimeZone localTimeZone]secondsFromGMT]];
        [newDateArray addObject:dateOnly];
    }
    

    2) Now that you have a new array consisting of NSDate objects with zeroed time components, you can sort them:

    [newDateArray sortUsingSelector:@selector(compare:)];
    

    This line sorts the array using the NSDate object’s own comparator method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I sort a 2D array in PHP. I want to sort on
I want to sort multidimensional array values from not null to null. I want
I want to sort my array.... In my array elements are in this order
I want to sort an array by using uasort() function. I wrote this piece
Can anyone tell me how to sort an array by key? I want to
$array = array(2011-September_38,2011-June_4,2010-November_9,2011-November_29,2010-December_19); i want to sort this array strings as following, it should
I've a big problem. I want to sort an array like this: '0' ...
I want to sort my array: p1q1 p1q10 p1q2 to this order: p1q1 p1q2
I want to sort an array that looks like this (to numerical order instead
I want to make an array sort method so you can sort some info

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.