0

i hav a two dates of type nsdate and i want to calculate the diff b/w the two dates as a mins/seconds finally...

how can i do it..

Linux world
  • 3,724
  • 11
  • 42
  • 59

3 Answers3

1

NSDate has a -timeIntervalSinceDate: method.


EDIT

Therefore:

NSTimeInterval tval = [date1 timeIntervalSinceDate: date2];
int sec = tval % 60,
    min = tval - 60*sec;
Community
  • 1
  • 1
Alexsander Akers
  • 15,899
  • 12
  • 56
  • 83
0

http://iphonedevelopment.blogspot.com/2009/07/category-on-nsdate.html

as you get the days you can convert into time.

But if you want exact difference , like if it is 1.5 days

you have to convert date into timestamp then find the difference

iPhone: Convert date string to a relative time stamp

Community
  • 1
  • 1
zod
  • 11,702
  • 23
  • 66
  • 104
0

So Alexsander want to say you take this:

double difference = [date1 timeIntervalSinceDate:date2] / 60;
The difference is now in minutes.
Christian 'fuzi' Orgler
  • 1,624
  • 8
  • 27
  • 50