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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:19:32+00:00 2026-05-23T11:19:32+00:00

I have a date coming from the database which in this format 2011-11-30 18:38:00

  • 0

I have a date coming from the database which in this format 2011-11-30 18:38:00 +0000 and i need date difference from now.How it’s is possible?this what i am doing:-

  NSDate* pDateEnd;



  NSLog(@"PDateEnd=%@",pDateEnd); //it has value=2011-11-30 18:38:00 +0000

NSTimeInterval secForDeal = [pDateEnd timeIntervalSinceNow];

NSLog(@"secForDeal=%i",secForDeal);
if(secForDeal < 0)
    return nil;
//////
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
NSCalendar *currentCalendar = [NSCalendar currentCalendar];

NSDateComponents* pRemainingDate = [[[NSDateComponents alloc] init] autorelease];

[pRemainingDate setHour:0];

[pRemainingDate setMinute:0];

[pRemainingDate setSecond:secForDeal];

//preparing date 
NSDate *date = [currentCalendar dateFromComponents:pRemainingDate];
//again splitting date to components
NSDateComponents *comps = [currentCalendar components:unitFlags fromDate:date];
/////Generating the date
NSString* pRetTimeRemaining = [NSString stringWithFormat:@"%i Year %i Month %i days %i Hr %i Min",[comps year],[comps month],[comps day],[comps hour],[comps minute]];
///////
NSLog(@"pRetTimeRemaining=%@",pRetTimeRemaining);
return pRetTimeRemaining;

Please tell if there is any error or another way to do this.Thank you.

  • 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-23T11:19:32+00:00Added an answer on May 23, 2026 at 11:19 am

    Try following code for get number of days, min, hrs, months between two dates.

    // The time interval 
    NSTimeInterval theTimeInterval = 326.4;
    
    // Get the system calendar
    NSCalendar *sysCalendar = [NSCalendar currentCalendar];
    
    // Create the NSDates
    NSDate *date1 = [[NSDate alloc] init];
    NSDate *date2 = [[NSDate alloc] initWithTimeInterval:theTimeInterval sinceDate:date1]; 
    
    // Get conversion to months, days, hours, minutes
    unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
    
    NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:date1  toDate:date2  options:0];
    
    NSLog(@"Conversion: %dmin %dhours %ddays %dmoths",[conversionInfo minute], [conversionInfo hour], [conversionInfo day], [conversionInfo month]);
    
    [date1 release];
    [date2 release];
    

    Try following code for get number of days between two dates.

    -(int)howManyDaysHavePast:(NSDate*)lastDate today:(NSDate*)today {
        NSDate *startDate = lastDate;
        NSDate *endDate = today;
        NSCalendar *gregorian = [[NSCalendar alloc]
                                 initWithCalendarIdentifier:NSGregorianCalendar];
        unsigned int unitFlags = NSDayCalendarUnit;
        NSDateComponents *components = [gregorian components:unitFlags
                                                    fromDate:startDate
                                                      toDate:endDate options:0];
        int days = [components day];
        return days; // multiply by 24 for get remain hrs.
    }
    

    Or fololw

    • How can i get the Date Difference?

    • How to convert an NSTimeInterval (seconds) into minutes

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

Sidebar

Related Questions

I have an array coming from my database I want to format and display
i have one table in my database say mytable, which contents request coming from
I'm having trouble with this query. I have 2 date coming from textboxes (don't
I have a date converted to double value and saved in database. Now, I
I have a video gallery where the data is coming from a mysql database.
I am querying tables from Microsoft SQL 2008 which have date split across 3
I have a date coming through from a .NET webservice into my Rails app:
In my grid data store, I have a date field which contains data coming
I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @MMM dd,
I have start date and end date. I need to find out the day

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.