> 
> **Possible Duplicate:**  
> 
> [iPhone: Convert date string to a relative time stamp](https://stackoverflow.com/questions/902950/iphone-convert-date-string-to-a-relative-time-stamp) 
> 
> 
> 

I have a problem. I have tried creating a way to get a time since stamp such as "14 hours ago" but it doesn't seem to be working. So I need to help to create a function that takes seconds from the time a database row/item was created. So if the db row was created 600 seconds ago that would mean the function would output "10 minutes ago"? I want it to return either seconds, minutes, hours, weeks, months or years. I know its probably really simple, I just can't seem to get it right...

OH and this is for an iPhone app so it uses objective-c.

Any help would be much appreciated.

THIS IS WHAT I HAVE CURRENTLY:

```
-(NSString *)timeSinceTimestamp:(NSString *)seconds{
   double seconds2 = [seconds doubleValue];
   NSDate *date = [NSDate dateWithTimeIntervalSince1970:seconds2];
   NSDate *now = [NSDate date];
   double start = [date timeIntervalSince1970];
   double end = [now timeIntervalSince1970];
   double difference = (end - start) / 1000;
   difference = round(difference);
   int minutes = difference / 60;
   int hours = minutes / 60;
   int days = hours / 24;
   int weeks = days / 7;
   int months = weeks / 5;
   int years = months / 12;
   NSString *string;
   if(difference < 60){
        string = [NSString stringWithFormat:@"%i seconds ago",difference];
   }else if (minutes > 1 && minutes < 60) {
        string = [NSString stringWithFormat:@"%i minutes ago",minutes];
   }else if (hours > 1 && hours < 24) {
       string = [NSString stringWithFormat:@"%i hours ago",hours];
   }else if (days > 1 && days < 7) {
       string = [NSString stringWithFormat:@"%i days ago",days];
   }else if (weeks > 1 && weeks < 5) {
       string = [NSString stringWithFormat:@"%i weeks ago",weeks];
   }else if (months > 1  && months < 12) {
       string = [NSString stringWithFormat:@"%i months ago",months];
   }else if (years > 1 && years < 12) {
       string = [NSString stringWithFormat:@"%i years ago",years];
   }

     return string;
}

```