Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 482681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:07:14+00:00 2026-05-13T01:07:14+00:00

I have two time values in HH:mm format that I need to compare, and

  • 0

I have two time values in HH:mm format that I need to compare, and return how many minutes they differ by. For example comparing 18:30 and 19:45 should return 1:15. I’ve read up on NSDate, NSCalendar, and so on, but I am confused as to how they all work together and how I would create an NSDate with only a time, not an entire date.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:07:15+00:00Added an answer on May 13, 2026 at 1:07 am

    You could use NSDateFormatter to create NSDate objects given strings in “HH:mm” format, and then use -[NSDate timeIntervalSinceDate:] to find the number of seconds between the two times. NSDate encapsulates a full date – you can’t have it represent only a time – so the NSDate objects created will be a time on a specific date (the reference date, Jan 1st 1970, from my testing) in the local time zone. You’ll need to decide for yourself whether you need a more robust solution to fit your needs since your needs are unclear.

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm"];
    NSDate *time1 = [formatter dateFromString:@"18:30"];
    NSDate *time2 = [formatter dateFromString:@"19:45"];
    [formatter release];
    
    NSTimeInterval deltaTime = fabs([time1 timeIntervalSinceDate:time2]);
    NSString *result = [NSString stringWithFormat:@"%d:%d", (int)(deltaTime/3600), (int)(deltaTime/60)%60];
    

    With the fabs() wrapping the timeIntervalSinceDate: there, you won’t get a negative time based on the ordering of the receiver and argument for timeIntervalSinceDate:. You can adjust that if needed.

    Note: The above probably isn’t the best or most efficient way ever to determine the result, but I was just aiming to illustrate the concept, not optimize unnecessarily.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 256k
  • Answers 256k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try sprintf return sprintf("%02:%02d:%02d", $hours, $minutes, $diff); May 13, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer It turns out a decent solution is to wrap the… May 13, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer There is JempBox which is open source and allows the… May 13, 2026 at 10:28 am

Related Questions

I extracted year, month, day, hour, minute, second, and millisecond data from human readable
I have a custom validator that points to a Client side script to validate
Here is the situation: I have a table value function with a datetime parameter
I have two arrays with time values in them in this format. 00:00:00 which

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.