Microsoft KB Archive/171060

From BetaArchive Wiki
Knowledge Base

PRJ: DateAdd and DateDifference Methods Don't Work

Article ID: 171060

Article Last Modified on 1/20/2007


  • Microsoft Project 2000 Standard Edition
  • Microsoft Project 98 Standard Edition

This article was previously published under Q171060


In Microsoft Project 98 or later, when you attempt to use a Microsoft Project version 4.0 or Microsoft Project for Windows 95, version 4.1, macro that uses the Visual Basic for Applications DateAdd or DateDifference method, it does not function correctly.


This behavior occurs in Microsoft Project 98 or later because the DateAdd or DateDifference methods must be fully qualified by the Application object or they will not function correctly.


Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this behavior, in Microsoft Project 98 or later, precede the DateAdd or DateDifference method with Application. For example to use the DateDifference command in Microsoft Project 98 or later, change this code

   Sub Test()
      MsgBox DateDifference("1/1","6/1")
   End Sub

to this:

   Sub Test()
      MsgBox Application.DateDifference("1/1","6/1")
   End Sub

Additional query words: prj2000

Keywords: kbmacro kbprb kbprogramming KB171060