Get Duration by Start and Finish

Hi,

How can I get duration of a task by supplying Start and Finish dates?

Hi Ali,


Thank you for contacting Aspose.

Tasks are created by providing the task start date and duration and thus the Finish dates are auto-calculated. However we can get duration by using Start and finish date as given in the sample code below:

Project prj = new Project();
Task tsk = prj.AddTask(“Task 01”);
tsk.Start = DateTime.Parse(“2014/01/21 08:00:00”);
tsk.Duration = prj.Calendar.GetWorkingHours(tsk.Start, DateTime.Parse(“2014/01/22 17:00:00”)).WorkingHours;
Console.WriteLine(“Duration = " + tsk.GetDuration(TimeUnitType.Day) + " days”);
Console.WriteLine("finish Date = " + tsk.Finish);
Here we can see that duration is set to 02 days because we have calculated the duration and then assigned it to task. At the end, if you display task finish date, its auto-calculated (as expected) and is equal to the supplied finish date and time.

Please feel free to write us back if you have any other query in this regard.
Hi Kashif,
Thanks for your quick reply.