- Home /
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.
Answer by juicyz · Jan 04, 2017 at 12:13 AM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612103958im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Save current time on quit, then on relaunch compare to new current time and get difference? 3 Answers
Check How Many Minutes Have Passed 1 Answer
Creating a Circular Progressbar / Timer 6 Answers
Progression bar that shows time left of animation? 1 Answer
GUI.Drawtexure progressbar dissapears, when it should just look shorter. 1 Answer