Percentage between DateTime

Hello,

I’m working on a time based game, and I want to be able to present a progress bar that represents how much time is left.

The progress bar needs a percentage for the value - well, actual between 0.0 and 1.0.

I have two DateTime variables, _start, which is just a fixed previous time for now. And _remain, which is the _start time, with a minute added to it

System.DateTime _start = StartingTime();
System.DateTime _remain = _start + AddOneMinute();

I need to somehow now find a 0.0 - 1.0 value from this? But I’m not quite sure how? Thanks.

To clarify what I think you said is that you have a start time defined as _start. And the end time _remain.
You now what to make a progress bar for how much time is left between _start and _remain?

You would need another variable to hold the current time then you can do, (current - start) / (remain - start)

For example if start was 2oclock. Then start would be 2:00. Remain would be 2:01. Say Current was 2:00:30. The above equation would give you (2:00:30 - 2:00) / (2:01 - 2:00) which would simplify to .5 minutes / 1 minute. AKA 50% (.5).

If your timer is always only 1 minute, then you could just do, current - start.