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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:04:40+00:00 2026-05-31T08:04:40+00:00

I am trying to calculate an interval between now and a user defined date

  • 0

I am trying to calculate an interval between now and a user defined date in days so that the results appear in a label on tapping a button.

The difference is always -4080 I am not sure what is wrong with my equation.
Thank you for your help

- (void)LabelChange2:(id)sender{
    NSDateFormatter *df3 = [[NSDateFormatter alloc] init];
    df3.dateStyle = NSDateFormatterMediumStyle;
    labelDOB.text = [NSString stringWithFormat:@"%@",
                     [df3 stringFromDate:datepick.date]];
}



  NSDate * df3 = [datePick date];
    NSCalendar *gregorian = [[NSCalendar alloc] 
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *comps = [gregorian components: NSDayCalendarUnit 
                                           fromDate: [NSDate date]  
                                             toDate: df3 
                                            options: 0];
    int days = [comps day];
    labelResult.text = [NSString stringWithFormat:@"%i", days];
  • 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-31T08:04:42+00:00Added an answer on May 31, 2026 at 8:04 am

    Your code works fine. However if I run the code with the datePick pointer set to nil I will get an answer of -4080 from this code. You should check your connections to the UIDatePicker.

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

Sidebar

Related Questions

I'm trying to calculate the difference between 2 dates, the current date and the
I'm trying to calculate time blocks from given date range. Here's my attempt: <?php
I'm trying to calculate TimeSpans between dates. I have no problem with this if
I am trying to calculate the distance between the first GPS point stored in
I am trying to calculate last years starting day of the current week NOW()
I am trying to calculate the difference between given two times and i find
I'm trying to calculate whether the results i get from the database are made
I'm trying to calculate a distance between two sets of coordinate points in an
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I'm trying to calculate correlations in Perl. I found out how to calculate correlations

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.