Hi all,
I'm have the following info in my database:
date,
timefrom,
timetill
(I'm using timefrom and timetill, to make it easier with showing these info)
Now I calculate the difference between these times like this:
Now I have a difference like: 3.500 hours.
Now I want it to be: 3:30 hours
Whats the easiest way to accomplish this?
I can start storing the value as string, explode it on .
if the 2nd value is bigger than 0 then, I can devide 60 by this number and glue it back together and seperate it by a :
There must be an easier way!
I'm have the following info in my database:
date,
timefrom,
timetill
(I'm using timefrom and timetill, to make it easier with showing these info)
Now I calculate the difference between these times like this:
Code:
NSString *start = [[agendaItems objectAtIndex:indexPath.row] objectAtIndex:indexOfStarttime];
NSString *end = [[agendaItems objectAtIndex:indexPath.row] objectAtIndex:indexOfEndtime];
NSString *date = [[agendaItems objectAtIndex:indexPath.row] objectAtIndex:indexOfDate];
NSString *startDate = [NSString stringWithFormat: @"%@ %@", date, start];
NSDateFormatter* fmt1 = [NSDateFormatter new];
[fmt1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *eindDatum = [NSString stringWithFormat: @"%@ %@", date, end];
NSDateFormatter* fmt2 = [NSDateFormatter new];
[fmt2 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date1 = [fmt1 dateFromString: startDatum];
NSDate *date2 = [fmt1 dateFromString: eindDatum];
NSTimeInterval distanceBetweenDates = [date1 timeIntervalSinceDate:date2];
double diffInHours = distanceBetweenDates / 3600;
//p.s. I should be doing it other way around so I dont need to use fabs(diffInHours) I know ;-)
Now I have a difference like: 3.500 hours.
Now I want it to be: 3:30 hours
Whats the easiest way to accomplish this?
I can start storing the value as string, explode it on .
if the 2nd value is bigger than 0 then, I can devide 60 by this number and glue it back together and seperate it by a :
There must be an easier way!
Last edited: