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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:49:35+00:00 2026-06-15T14:49:35+00:00

I need to fetch objects from core data within specific time periods; i.e. weekly

  • 0

I need to fetch objects from core data within specific time periods; i.e. weekly, monthly, yearly.

I would then feed the dates generated from the components into a predicate like this:

[NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@", 
                                 intervalStartDate, intervalEndDate];

Examples of intervals/periods:

          start          end            start          end
weekly    Jan 2, 2012 to Jan 08, 2012,  Jan 9, 2012 to Jan 15, 2012,  etc.
monthly   Jan 1, 2012 to Jan 31, 2012,  Feb 1, 2012 to Feb 29, 2012,  etc.
yearly    Jan 1, 2011 to Dec 31, 2011,  Jan 1, 2012 to Dec 31, 2012,  etc.

With these, I could get the specific objects during that time period.

My problem is, that I don’t know what would be the best way to increment the date components. I have to account for leap years, etc.

What would be the best way to achieve 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-06-15T14:49:37+00:00Added an answer on June 15, 2026 at 2:49 pm

    As long as you use the correct NSCalendar and as long as you treat each calculation of dates independent of each other, the resulting dates should be fine.

    NSDateComponents *dateOffset = [[NSDateComponents alloc] init];
    [dateOffset setWeek:1]; // weekly
    // [dateOffset setMonth:1]; // monthly
    // [dateOffset setYear:1]; // yearly
    
    NSDate *endDate = [gregorian dateByAddingComponents:dateOffset toDate:startDate options:0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I want to fetch objects from my core data
I need to fetch data from normalized MSSQL db and feed them in Solr
Im using vb.net and I need to fetch data from two different tables and
I am fetching a set of objects from a Core Data persistent store using
I am working on a project where we need to fetch data from a
Lets say I need to fetch some records from the database, and filter them
I often need to fetch tgz files, decompress them, and then delete the tgz.
I have a Core Data database of about 500 objects. These objects are 'cards'
I have Core Data working in my app. So, I fetch an XML file,
I am writing a Core Data app and I've started passing my objects around

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.