PRJ4: Converting Duration Values

ID: Q132092

The information in this article applies to:

SUMMARY

The DurationValue method in Microsoft Project is used to convert a duration value into the equivalent number of minutes. This conversion is always based on the current conversion defaults for the application, rather than the conversion defaults for a specific project.

A custom function can be used in place of DurationValue to return values based on project-specific conversion defaults.

MORE INFORMATION

The DurationValue method takes a duration value as a string argument and returns an integer number of minutes. If the duration value is specified in units of Days or Weeks, this conversion is based on the current application default values for Hours Per Day and Hours Per Week. For example, with the initial default value for Hours Per Day set to 8.00 using this value, 5d = 40h = 2400m; Application.DurationValue("5d") = 2400.

Changing the Hours Per Day setting for a specific project does not affect this calculation. For example, making the following change will not affect this calculation:

1. On the Tools menu, click Options.

2. Select the Calendar tab.

3. In the Hours Per Day box, type "7.00" (without the quotation marks), and

   choose OK.

This procedure changes the Hours Per Day value for the current project only. In this situation, Application.DurationValue still returns 2400 because this method operates at the application level not the project level.

To change the default value for the entire application

1. On the Tools menu, click Options.

2. Select the Calendar tab.

3. In the Hours Per Day box, type "7.00" (without the quotation marks).

4. Choose the Set as Default button.

5. Choose the OK button.

After you make this change, Application.DurationValue("5d") = 2100. (5d = 35h = 2100m)

It is also possible to create an equivalent function that returns the number of minutes based on the conversion settings in a particular project. The following example ProjDurationValue function takes a project object and a duration string as arguments, and returns the corresponding number of minutes for that duration.

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

Sample Macro

Function ProjDurationValue(oProj As Object, sDur As String) As Long

' This function returns the number of minutes equivalent
' to the passed duration based on conversion values in the
' passed project.
' ProjDurationValue returns -1 if an invalid duration value is passed.

' oProj = project whose conversion values we're using
' sDur  = duration to convert

   ProjDurationValue = -1        ' Return -1 if invalid duration

   If InStr(sDur, "e") > 0 Then  ' Elapsed duration
      Select Case Right(sDur, 2)
         Case "ed"   ' Elapsed days
            '1440 = number of minutes in 1 elapsed day
            ProjDurationValue = Val(sDur) * 1440
            Exit Function
         Case "ew"   ' Elapsed weeks
            '10080 = number of minutes in 1 elapsed week
            ProjDurationValue = Val(sDur) * 10080
            Exit Function
      End Select
   End If

   Select Case Right(sDur, 1)
      Case "m"    ' Minutes and Elapsed Minutes
         ProjDurationValue = Val(sDur)
      Case "h"    ' Hours and Elapsed Hours
         ProjDurationValue = Val(sDur) * 60
      Case "d"    ' Days
         Temp = oProj.Duration1
         oProj.Duration1 = "1d"
         ProjDurationValue = Val(sDur) * 60 * (oProj.Duration1 / 60)
         oProj.Duration1 = Temp
      Case "w"    ' Weeks
         Temp = oProj.Duration1
         oProj.Duration1 = "1w"
         ProjDurationValue = Val(sDur) * 60 * (oProj.Duration1 / 60)
         oProj.Duration1 = Temp
   End Select

End Function

Additional query words: 4.00

Keywords          : kbcode kbprg
Version           : 4.0 4.1 98
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: November 18, 1998