Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I try to call MSProjectApplication.DateDifference from a C# application. The version of MSProject is 2003, and I'm using Visual Studio 2010, running on Windows 7.

private Project.Application m_pr;

....
Project.Task oldTask;
Project.Task newTask;


....

int duration;
duration = m_pr.DateDifference(newTask.Start, oldTask.Finish);



The code compiles without any errors or warnings. However, when I run it I get a System.NotImplementedException when it tries to call the DateDifference function. Any other MSProject related function call that I used in the code works fine; Calling DateDifference directly from MSProject (as VBA macro) also works. I'm unsure whether this function really has not been implemented, or whether I'm doing something wrong.


As a workaround, I currently create a new task in MSProject with the two dates fixed, and read the duration, but that seems not to be a very elegant solution. Any other ideas?



Regards,

Andreas
Posted
Updated 2-Feb-12 15:01pm
v3
Comments
Rajesh Anuhya 2-Feb-12 20:58pm    
Edited: Code Tags added
--RA

1 solution

if start and finish are objects of type DateTime
if newTask.Start is greater than oldTask.Finish


C#
int duration = newTask.Start.Subtract(oldTask.Finish).Days;
 
Share this answer
 
v2
Comments
hal64 3-Feb-12 3:46am    
Hi,

thanx, but that doesn't work - at least not as required. The duration above gives the total number of days between the two dates. What I need is the number of working days according to the basecalendar in MSProject.

Regards,

Andreas

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900