Start New Discussion within our Software Development Community

I am not sure how to accomplish this, but I am trying to take a dates from two fields and using the current date show the progress percentage in a different field.

So, if past date is Jan 1st, the current date is Jan 5th, the future date is Jan 10th. How do I get a percentage of completion between Jan 1st and Jan 10th based on today's date Jan 5th?

Try to work with numbers. And using DateDiff function.
Dates are numbers, so, it simplify your work! ;)


I will work with Jan 11th, only for rounding numbers, right?

Dim nDiasTotal as Integer, nDiasPassados as Integer

'GET DIFFERENCE BETWEEN JAN 1st AND JAN 11th
nDiasTotal = DateDiff("d", "01/01/2010", "11/01/2010")
'GET DIFFERENCE BETWEEN TODAY (ASSUMING TODAY IS JAN 6th) AND FIRST DATE
nDiasPassados = DateDiff("d", "01/01/2010", Date)

'CALCULATE PERCENTAGE OF PAST DAYS
MsgBox (nDiasPassados / nDiasTotal) * 100 & " % past time"
'CALCULATE PERCENTAGE OF REMAINING TIME
MsgBox 100 - ((nDiasPassados / nDiasTotal) * 100) & " % remaining time"

Hope it helps!

Sidnei

This article has been dead for over six months. Start a new discussion instead.