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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:45:01+00:00 2026-06-18T07:45:01+00:00

I am using this code to block the user from going over the limit

  • 0

I am using this code to block the user from going over the limit I set:

in view did load:

NSDate *Date=[NSDate date];
[DatePickerForDate setMinimumDate:Date];
[DatePickerForDate setMaximumDate:[Date dateByAddingTimeInterval: 63072000]]; //time interval in seconds

And this method:

- (IBAction)datePickerChanged:(id)sender{
if ( [DatePickerForDate.date timeIntervalSinceNow ] < 0 ){
    NSDate *Date=[NSDate date];
    DatePickerForDate.date = Date;
}

if ( [DatePickerForDate.date timeIntervalSinceNow ] > 63072000){
    NSDate *Date=[NSDate date];
    DatePickerForDate.date = Date;
}
}

The first part works (the one with <0), and returns to the current date, but the one > 63072000, sometimes works and sometimes doesn’t. By the way 63072000 is about 2 years. Any ideas?

  • 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-18T07:45:02+00:00Added an answer on June 18, 2026 at 7:45 am

    I experimented using a UIDatePicker with a maximumDate of one month from now:

    NSDate* now = [NSDate date] ;
    // Get current NSDate without seconds & milliseconds, so that I can better compare the chosen date to the minimum & maximum dates.
    NSCalendar* calendar = [NSCalendar currentCalendar] ;
    NSDateComponents* nowWithoutSecondsComponents = [calendar components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit) fromDate:now] ;
    NSDate* nowWithoutSeconds = [calendar dateFromComponents:nowWithoutSecondsComponents] ;
    //  UIDatePicker* picker ;
    picker.minimumDate = nowWithoutSeconds ;
    
    NSDateComponents* addOneMonthComponents = [NSDateComponents new] ;
    addOneMonthComponents.month = 1 ;
    NSDate* oneMonthFromNowWithoutSeconds = [calendar dateByAddingComponents:addOneMonthComponents toDate:nowWithoutSeconds options:0] ;
    picker.maximumDate = oneMonthFromNowWithoutSeconds ;
    

    I found that:

    • The first time you attempt to select a date outside of the minimum and maximum range, the UIDatePicker will scroll itself back “in range”.
    • If you immediately select a date out of range again, the Picker will not scroll back, allowing you to select a date out of range.
    • If the Picker’s selected date is out of range, its date property will return the nearest date that’s in range.
    • When you call setDate: or setDate:animated:, if the date you pass is the exact same date returned by the Picker’s date property, the Picker will do nothing.

    With that in mind, here is a method that you can call when the Picker’s value changes that prevents you from ever selecting a date out of range:

    - (IBAction) datePickerChanged:(id)sender {
        // When `setDate:` is called, if the passed date argument exactly matches the Picker's date property's value, the Picker will do nothing. So, offset the passed date argument by one second, ensuring the Picker scrolls every time.
        NSDate* oneSecondAfterPickersDate = [picker.date dateByAddingTimeInterval:1] ;
        if ( [picker.date compare:picker.minimumDate] == NSOrderedSame ) {
            NSLog(@"date is at or below the minimum") ;
            picker.date = oneSecondAfterPickersDate ;
        }
        else if ( [picker.date compare:picker.maximumDate] == NSOrderedSame ) {
            NSLog(@"date is at or above the maximum") ;
            picker.date = oneSecondAfterPickersDate ;
        }
    }
    

    The above if and else if sections are nearly identical, but I kept them separate so that I could see the different NSLogs, and also to better debug.

    Here’s the working project on GitHub.

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

Sidebar

Related Questions

Possible Duplicate: UIDatePicker set Maximum date I am using this code to block the
I am using this block of code to mimic the way files are uploaded:
I seem to be using this block of code alot in Python. if Y
I'm using Drupal 7. And i created a block and embed this code: $contents
I am using the Mongo Ruby driver and have this block of Ruby code
I'm using this code block to get the font name, style and size selected
I am using jquerymobile ,this code shows list with the colors of data-theme (black),
Using this code, i am able to send a notification to my own device.
Using this code to zip a folder and it works perfect on small files
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:

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.