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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:18:35+00:00 2026-05-29T06:18:35+00:00

In my app I would like to allow the user to enter a value

  • 0

In my app I would like to allow the user to enter a value only once a day.

How do I make sure the the stored NSDate is not within the current day? Can I compare the day value of two NSDate while ignoring the time?

  • 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-29T06:18:36+00:00Added an answer on May 29, 2026 at 6:18 am

    Dates are just wrappers around NSTimeIntervals. They have no concept of local time, so you can’t get a day value out of them directly.

    You could use NSDateFormatter, like this:

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy/MM/dd"];
    
    NSString *today = [formatter stringFromDate:[NSDate date]];
    
    NSString *dateToCompare = [formatter stringFromDate:someDate];
    
    if ([dateToCompare isEqualToString:today])
    {
        ...
    }
    

    Date formatters output the date using your local timezone, so you can guarantee that the day will be correct for the user.

    If you actually want to ensure that the events are more than 24 hours apart (to prevent cheating) it’s much easier, just do this:

    if ([date1 timeIntervalSinceDate:date2] > 3600*24)
    {
        ...
    }
    

    UPDATE: As pointed out by abbood in the comments, it can be expensive/slow to create NSDateFormatter objects, so you should hang onto them if they will be reused.

    It isn’t a good idea to store them in a static variable or singleton because they are not thread-safe, but you can store them in the current thread’s threadDictionary, like this:

    //check for a cached formatter and recreate if needed
    NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
    NSDateFormatter *formatter = threadDict[@"someUniqueKey"];
    if (!formatter)
    {
        //create the formatter
        formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy/MM/dd"];
    
        //cache the formatter
        threadDict[@"someUniqueKey"] = formatter;
    }
    
    //use the formatter
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to allow users to call my ruby on rails app as
I'm developing an ASP.NET Web app and would like the user to be able
I am writing an opengl based iphone app and would like to allow a
My problem is: I would like to allow my user to pin single element
I would like to create a grid line approach in my app and allow
After a user has provided me their oauth credentials, I would like to allow
I would like to add buttons which allow the user to buy music on
I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would
I would like to use Public/Private encryption where my web app would sign an
I have an iPhone app and would like to create iPad version of it.

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.