I am not sure how to accomplish this, but I am trying to take 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 "x", the future date is Jan 11th. How do I get a percentage of completion between Jan 1st and Jan 11th based on today's date Jan 5th?

BDate | EDate | % to completion
Jan 1st | Jan 11th | %

Here's some code that does the work that would be compatible between VB and C# (syntax aside)

Sub Main()

        Dim pastDate As DateTime = New DateTime(2010, 1, 1)
        Dim targetDate As DateTime = New DateTime(2010, 1, 31, 23, 59, 59)
        Dim currentDate As DateTime = DateTime.Now

        'percentage in this example is in terms of minutes
        Dim totalMinutes As Double = targetDate.Subtract(pastDate).TotalMinutes
        Dim currentMinutes As Double = currentDate.Subtract(pastDate).TotalMinutes

        Dim percentComplete As Double = currentMinutes / totalMinutes
        Console.WriteLine("The time period is {0} complete", percentComplete.ToString("0.00%"))
        Console.Read()

    End Sub

Apegram that worked great!!

Now I'm having a problem with items being over 100%. How would I add something in to make it so that if it is 100% or greater it would say "100% complete".

Apegram that worked great!!

Now I'm having a problem with items being over 100%. How would I add something in to make it so that if it is 100% or greater it would say "100% complete".

Just check if percentComplete (the variable I used) is greater than 1. If so, set it to 1.

If percentComplete > 1.0 Then
     percentComplete = 1.0
End If

Thanks again. This is the last one. I'm learning alot here.

What if there is no value for the past date or target date? How do I produce it to say "data needs to be filled"?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.