Question

I'm trying to figure how you can add a birthday to an ABRecordRef without a year (i.e May 5 instead of May 5 1985). Is this possible?

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy"];
NSDate *date = [df dateFromString:[result valueForKey:@"birthday"]];

if(date == nil)
{
       df = [[NSDateFormatter alloc] init];
       [df setDateFormat:@"MM/dd"];
       date = [df dateFromString:[result valueForKey:@"birthday"]];
 }

 ABRecordSetValue(person, kABPersonBirthdayProperty, (__bridge CFDateRef)date, nil);

If there's no year attached to the date string it defaults to 1970 but I want it to put it without a year in the address book if that's at all possible.

Anyone knows?

Was it helpful?

Solution

I'm afraid thats not possible. Just use the current year or the unix reference date, so you'll have at least the day and month right.

OTHER TIPS

You can set a birthdate to a contact (through the Contacts app) with only a month/day. The year is then set to 1604, it's just not shown. If before you do your ABRecordSetValue(), you set the year to 1604, the birthdate will show as just "May 5" when viewing the contact in the Contacts app. It appears as though this is the way Apple specifies 'no year'. You will have to manually check the date later if you plan on showing it otherwise you will display the 1604 year.

You can do this by setting the year of the birthday to 1604, and this will only work with the Gregorian calendar.

See this question and answer for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top