0

I have some data which contains sold date. I want to sort them according to Week, Month, Year. For eg. If I select week then results returned should be within 7 days of current date. Same goes for Month and Year.

The relevant field from the data which is fetched from a web service looks like the following:

AuctionStartTime = "05/03/2016 09:30:00 AM"
Sanket_B
  • 735
  • 9
  • 26
  • How and where is this data stored? What does it look like? – ZeMoon Mar 07 '16 at 10:20
  • data comes from web service – Sanket_B Mar 07 '16 at 10:21
  • Could you give us an example of what the data looks like in the web service's response? – ZeMoon Mar 07 '16 at 10:21
  • AuctionStartTime = "05/03/2016 09:30:00 AM"; – Sanket_B Mar 07 '16 at 10:25
  • are you using model? – techloverr Mar 07 '16 at 10:27
  • 2
    You need to give us the the possibles parameters for you WebService API. Then, you need to tell us where lies exactly your issue, if it's really possible to fetch between dates with your WS. Else, it's just a matter on how to create a startDate (beginning of the week/month/year), and an endDate (end of the week/month/year), issue that's have already been answered on SO. Or if you need to filter (`NSPredicate`), with possibly a `NSSortDescriptor` then. – Larme Mar 07 '16 at 10:27
  • @Larme and please ask if he want to sort or dictionary on using models so that we can help him to sort the date or string – techloverr Mar 07 '16 at 10:28

2 Answers2

1

You have use NSDateFormatter to convert the string to your date format and using NSDateFormat to get required date values and perform your task. The set date format using following code...

 NSDateFormatter *dateformat = [[NSDateFormatter alloc] init];
 [dateformat setDateFormat:@"Your Date Format"];

Convert string to date

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [dateFormatter dateFromString:dateStr];

The your date format to set your required format. For more details of date format to click now.

PT Vyas
  • 722
  • 9
  • 31
0

You shoud use a NSDateFormatter to convert the NSString date to NSDate then you can compare that to current date. After that you can easily pick the last week's, month's or year's dates.

Gulyás István
  • 173
  • 1
  • 5