Solved

# How do I subtract time?

Posted on 2010-08-18

I inputted some data from a text file such that nHour and nMinute is filled with an integer representing some hour and minute.

The time is represented using the 12h, not 24h, format. So 1:30pm is reflected by nHour = 1, and nMinute = 30, and there is a string strAMPM containing "AM" or "PM".

My question is I want to calculate how many minutes has elapsed since X, where X is a time in the past BEFORE nHour/nMinute has occurred, but within the same day.

So let's say nHour = 1, and nMinute = 30, and X = 9:00am. X may be whatever data type you need it to be but it has to represent some time value that I can modify/change in the future.

The answer to how much time has elapsed should be 270 (representing the 270 minutes difference between 9:00am and 1:30pm. How do I do this?

I can already envision the pseudo-code of how this would work, but I do not know the C++ functions that I would need to use and how to implement them. Thus, actual code that I can follow would be much appreciated.