Hello everyone,
I'd like to implement into my app a countdown of days until an expiration date that the user enters. I have 3 text fields; month, day, year. And a label; daysLabel. I'd like the user to be able to enter any date using the 3 text fields and when pressing an IBAction, daysLabel will display the amount of days until the expiration date. So far this is what I have and obviously it's not working:
Code:
- (IBAction)calcDays:(id)sender {
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm:ss"];
NSString *next = [[NSString alloc] initWithFormat: @"%@/%@/%@ 12:00:00 am", month.text, day.text, year.text];
NSDate *nextDate = [dateformatter dateFromString:next];
NSDate *today = [[NSDate alloc] init];
NSTimeInterval time = [today timeIntervalSinceDate:nextDate];
double numdays = time / 86400;
NSLog(@"numdays = %f/n", numdays);
[daysLabel setText:[NSString stringWithFormat:@"%f", numdays]];
[dateformatter release];
[next release];
}
Hope this isn't too dumb a question. Any help would be very much appreciated. Thank you all..