Jump to content

bodalal

bodalal

Member Since 27 Sep 2008
Offline Last Active Jul 14 2010 09:55 AM
-----

Topics I've Started

What's wrong with this Code? date calculate

02 July 2010 - 11:26 AM

hi all

My app contain Calendar date picker and label

when i chose date from Calendar picker as "Birth date"

then to calculate the age , it should calculate date between today (now) and the date in calendar picker

i did everything right in interface builder, then i wrote this code :

#import "AgeCalc.h"

@implementation AgeCalc

- (IBAction)calcut:(id)sender {
	
	NSDate *dBirth = [NSDate date];
	NSDate *today = [NSDate date];
	
	NSCalendar *gregorian = [[NSCalendar alloc]
							 initWithCalendarIdentifier:NSGregorianCalendar];
	
	unsigned int unitFlags = NSMonthCalendarUnit | NSDayCalendarUnit;
	
	NSDateComponents *components = [gregorian components:unitFlags fromDate:dBirth toDate:today options:0];
	int years = [components year];
	int months = [components month];
	int days = [components day];
	
	[txtResult setIntValue:years & @" Years " & months & @" Months" & days & @"Days"];
	
}
@end


Posted Image


BUT it does not work, nothing show up in the label

can any one help me plz.

thanx
© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy