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"
7
  • How and where is this data stored? What does it look like? Commented Mar 7, 2016 at 10:20
  • data comes from web service Commented Mar 7, 2016 at 10:21
  • Could you give us an example of what the data looks like in the web service's response? Commented Mar 7, 2016 at 10:21
  • AuctionStartTime = "05/03/2016 09:30:00 AM"; Commented Mar 7, 2016 at 10:25
  • 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. Commented Mar 7, 2016 at 10:27

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.