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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:12:19+00:00 2026-05-25T22:12:19+00:00

I have got some dates for some events and their ascending order from the

  • 0

I have got some dates for some events and their ascending order from the database .

Now , I want want some buttons ..

in this structure …

–######## Last Week #####—-
–######## yesterday #####—-

–######## today #####—-

–######## tomorrow #####—-
–######## Next Week #####—-

Now when I press the respected buttons ..
the events in that respected duration should be shown up ..

I mean all the data should be compared with today and all the data should be shorted by this order..

can anyone give me a idea or logic for this ?

  • 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-25T22:12:20+00:00Added an answer on May 25, 2026 at 10:12 pm

    The best way to deal with dates is by using NSDateComponents.
    for example, to get the date for tomorrow use:

    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *comp = [[[NSDateComponents alloc] init] autorelease];
    [comp setDay:1];
    NSDate *today = [NSDate date];
    NSDate *tomorrow = [cal dateByAddingComponents:comp toDate:today options:0];
    

    So, what you need to do is:

    1. Get the dates for all the relevant date categories
    2. When you push a button, build a predicate to retrieve only the objects between the two dates. For example, getting all the objects in the “tomorrow” category:

      NSPredicate *pred = [NSPredicate predicateWithFormat:@"date > %@ AND date < %@", tomorrow, nextWeek];
      

    You can use a small convenient method for getting the dates, by adding a category to NSDate with this method:

    @implementation NSDate (Components)
    
    -(NSDate *) dateByAddingCalendarUnit:(NSCalendarUnit)calendarUnit andCount:(NSInteger) count
    {
        NSDateComponents *comp = [[NSDateComponents alloc] init];
        switch (calendarUnit) {
            case NSSecondCalendarUnit:
                [comp setSecond:count];
                break; 
            case NSMinuteCalendarUnit:
                [comp setMinute:count];
                break; 
            case NSHourCalendarUnit:
                [comp setHour:count];
                break; 
            case NSDayCalendarUnit:
                [comp setDay:count];
                break;  
            case NSWeekCalendarUnit:
                [comp setWeek:count];
                break; 
            case NSWeekdayCalendarUnit:
                [comp setWeekday:count];
                break;
            case NSWeekdayOrdinalCalendarUnit:
                [comp setWeekdayOrdinal:count];
                break; 
            case NSMonthCalendarUnit:
                [comp setMonth:count];
                break; 
            case NSYearCalendarUnit:
                [comp setYear:count];
                break; 
            case NSEraCalendarUnit:
                [comp setEra:count];
                break; 
            default:
                break;
        }
    
        NSCalendar *cal = [NSCalendar currentCalendar];
        NSDate *newDate = [cal dateByAddingComponents:comp toDate:self options:0];
        [comp release];
        return newDate;
    }
    
    @end
    

    And use this method like this:

    NSDate *lastWeek = [[NSDate date] dateByAddingCalendarUnit:NSWeekCalendarUnit andCount:-1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got some javascript code and I'd like to convert this to C#.
I've got some Columns in a DataGridView that have their Binding property set to
I have got a piece of code, that should countdown some number (in this
I have a sql-query where I ask for some dates. "SELECT DISTINCT date FROM
I have got some events: some of them are continuous, some of them are
I just got some tweets using their XML feed, and have gotten the date/times
I'm a beginner in Java and I have got some problems with the static
I've got some 3rd party beans that have method signatures that fit quite well
I have got Sinatra/Rails app and an action which starts some long process. Ordinary
I have just installed Delphi 2010 and got some troubles with idHTTP component. If

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.