PDA

View Full Version : Date Issue




Josh Kahane
Aug 21, 2010, 09:53 AM
Hi

I have attempted this is many ways but failed consistently, hopefully you guys can help me achieve the what i want to do.

I am making an iPad app, I will have five tables in a single view and each table will have a date as a header/title in this format, e.g. Monday 20

These five tables will be monday to friday. This is the bit I cant do. I want to work out the current date and then highlight the table which is today, obviously changes everyday.

So for example, lets say today is Thursday 9th. Thursday table is highlighted and then is automatically sets the date of the other tables around thursday.

Think of a school timetable/planner/diary. Monday to friday, each labelled with their dates.

I hope this makes sense, if not let me know and I will try and visually represent this.



ranguvar
Aug 21, 2010, 02:01 PM
You might want to check out NSDate, NSDateComponents and NSDateFormatter. With these, your task should be really simple.

Josh Kahane
Aug 21, 2010, 03:06 PM
You might want to check out NSDate, NSDateComponents and NSDateFormatter. With these, your task should be really simple.

Well I have been using NSDate and NSDateFormatter like below, but no success:

NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"EEEE dd"];
NSDate *now = [[NSDate alloc] init];
NSString *dateString = [format stringFromDate:now];

dejo
Aug 21, 2010, 03:44 PM
...but no success
Please elaborate.

I threw your code above into a test project, added an NSLog(), and got:

2010-08-21 14:42:18.486 Untitled[71611:207] dateString = Saturday 21

Josh Kahane
Aug 21, 2010, 03:50 PM
Please elaborate.

I threw your code above into a test project, added an NSLog(), and got:

2010-08-21 14:42:18.486 Untitled[71611:207] dateString = Saturday 21

Of course, thats fine, it outputs the current date, but if I have a screen like attached. Now as far as I have gotten is get todays date showing.

On that screen, lets says its a Thursday, I want the thursday table to be highlighted and then the dates on the other tables are set, so if thursday is the 21st, make friday 22 and wednesday 20 etc

Hope you understand.

dejo
Aug 21, 2010, 04:05 PM
On that screen, lets says its a Thursday, I want the thursday table to be highlighted and then the dates on the other tables are set, so if thursday is the 21st, make friday 22 and wednesday 20 etc
Well, what have you tried already to get the current date highlighted? Also, what have you already tried to do to generate the previous and following dates? NSDate has a instance method that could be used to generate dates that are a given number of seconds relative to the current date.

Josh Kahane
Aug 21, 2010, 04:17 PM
Well, what have you tried already to get the current date highlighted? Also, what have you already tried to do to generate the previous and following dates? NSDate has a instance method that could be used to generate dates that are a given number of seconds relative to the current date.

Well I have pre named each table as they will always be fixed monday to friday, then checking that against the day I get from the NSDate.

Also, maybe what your talking about, from that used initWithTimeIntervalSinceNow.

Anyway I haven't succeeded, if it seems I should have, please let me know why, if not, how else could I achieve this? Thanks.

dejo
Aug 21, 2010, 04:24 PM
Anyway I haven't succeeded, if it seems I should have, please let me know why, if not, how else could I achieve this?
Well, I'm still not entirely certain what you've actually tried, so I'm not sure I'm in a position to tell you why you haven't had success yet.

Also, what happens when the current day is a Saturday or Sunday?

Josh Kahane
Aug 21, 2010, 04:35 PM
Well, I'm still not entirely certain what you've actually tried, so I'm not sure I'm in a position to tell you why you haven't had success yet.

Also, what happens when the current day is a Saturday or Sunday?

Nothing is highlighted if its saturday or sunday. This is because they aren't needed.

I will post back tomorrow with more detail of what i have tried, late here in the UK, thanks for the attempted help so far.

ranguvar
Aug 21, 2010, 04:43 PM
I don't know if I understand correctly, but it seems like you really just want to figure what day in the week the current day is. If that's the case, make sure you read this (http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns) document (linked to in the NSDateFormatter documentation!), specifically the "weekday" field.

Josh Kahane
Aug 22, 2010, 06:07 AM
http://stackoverflow.com/questions/3538941/use-of-nsdate-to-get-dates

What about this method? Would this work? Im not quite understanding it though.

ranguvar
Aug 22, 2010, 11:46 AM
http://stackoverflow.com/questions/3538941/use-of-nsdate-to-get-dates

What about this method? Would this work? Im not quite understanding it though.

Why don't you consider what I wrote in my previous post? Copy & paste without understanding won't get you anywhere (95% of iOS devs don't understand that).

chown33
Aug 22, 2010, 01:10 PM
Well I have pre named each table as they will always be fixed monday to friday, then checking that against the day I get from the NSDate.

Also, maybe what your talking about, from that used initWithTimeIntervalSinceNow.

Anyway I haven't succeeded, if it seems I should have, please let me know why, if not, how else could I achieve this? Thanks.

Post the actual code for what you described.

We can't debug descriptions.

Josh Kahane
Aug 22, 2010, 02:28 PM
Why don't you consider what I wrote in my previous post? Copy & paste without understanding won't get you anywhere (95% of iOS devs don't understand that).

Who ever said I didn't?! I did, and I know what you say is true, and I do read about it as thoroughly as I can, but when you simply don't understand where to go next, you ask for help, what I have done here.

Post the actual code for what you described.

We can't debug descriptions.

I will do, that makes sense.

ranguvar
Aug 23, 2010, 01:40 AM
Who ever said I didn't?! I did, and I know what you say is true, and I do read about it as thoroughly as I can, but when you simply don't understand where to go next, you ask for help, what I have done here.

Well, you got 5 tableviews, and I told you how to determine which day in the week a certain day is. From that, you can determine which tableview represents that day. What don't you understand?