I know that SQLite doesn’t support day name and month name. I have gone through this question. I have created two custom functions for it.
My custom function for Converting Day name from day number:
( %w day of week 0-6 with sunday==0 )
Code:
+(NSString*)dayNameStringFromDayNo:(NSString*)dayNo{
return
([dayNo isEqualToString:@"0"])?@"Sunday":
( ([dayNo isEqualToString:@"1"])?@"Monday":
( ([dayNo isEqualToString:@"2"])?@"Tuesday":
( ([dayNo isEqualToString:@"3"])?@"Wednesday":
( ([dayNo isEqualToString:@"4"])?@"Thursday":
( ([dayNo isEqualToString:@"5"])?@"Friday": @"Saturday"
)
)
)
)
);
}
My custom method for getting month name from month no string:
( %m month: 01-12 )
Code:
+(NSString*)monthNameFromNumber:(NSString*)no{
return ([no isEqualToString:@"01"])?@"January":
( ([no isEqualToString:@"02"])?@"February":
( ([no isEqualToString:@"03"])?@"March":
( ([no isEqualToString:@"04"])?@"April":
( ([no isEqualToString:@"05"])?@"May":
( ([no isEqualToString:@"06"])?@"June":
( ([no isEqualToString:@"07"])?@"July":
( ([no isEqualToString:@"08"])?@"August":
( ([no isEqualToString:@"09"])?@"September":
( ([no isEqualToString:@"10"])?@"October":
( ([no isEqualToString:@"11"])?@"November":@"Decemeber"
)
)
)
)
)
)
)
)
)
);
}
But what about date following format
Sat 6th February
How to get this kind of output ? Do I have to again create a custom function for it ?
What date format are you getting from SQLite? SQLite does not have a native date/time datatype, but it’s common to store a date as an ISO8601 string of the form
YYYY-MM-DD HH:MM:SSor a Unix-style timestamp.Step 1: Get the date as an
NSDate. Here’s one way, using the ISO8601 format mentioned above:If your date was stored as a Unix-style timestamp, you could skip using an input formatter and use
NSDate dateWithTimeIntervalSince1970:instead.Step 2: Convert the date to a string:
In this example you’ll get a string like
Sat 6 February, assuming the user is in an English locale.References: