0

I need to be able to store the current NS Date plus 7 days. I already store the current NSDate. I then want to compare the two dates, to get the number of days difference between the two and display within a label. The idea is to count down from 7 days, to 6 days, to 5 days, etc until it shows 0 and i will remove it from my tableview.

I have been having hard time finding the write code for this, so any help would be greatly appreciated!!!

mreynol
  • 309
  • 3
  • 17

1 Answers1

0

This code will compute date after 7 days from today.

NSDateComponents *comps = [NSDateComponents new];
comps.day = 7;

NSDate *today = [NSDate date];

NSCalendar *c = [NSCalendar currentCalendar];
NSDate *dateAfter7days = [c dateByAddingComponents:comps toDate:today options:0];

For Your date diffrence the code is:-

    // c is calendar object
    NSDateComponents *comps = [c components:NSDayCalendarUnit fromDate:startDate toDate:currentDate options:0];
    int diffrence = [comps day];
Abid Hussain
  • 1,529
  • 1
  • 15
  • 33
  • Actually, the date plus 7 days worked perfectly, but i'm having issue with the date difference. I'm getting warning: Incompatible pointer to integer conversion initializing 'int' with an expression of type 'NSDateComponents". – mreynol Nov 28 '12 at 04:21