I’m wondering how to compute the percentage between two DateTimes, I have a BackgroundWorker that executes until a provided DateTime is reached, that part is working fine, I just want to display in the UI what’s the percentage completed of the worker.
I tried to use the following approach:
var now = DateTime.Now;
var executeUntil = DateTime.Now..AddHours(4).AddMinutes(10);
var percentage = (int)(( executeUntil.Ticks * 100 ) / now.Ticks );
but is always returning 1, i’m guessing that this is because Ticks is a long number and somehow is truncating the division.
Any suggestions?
Try this: