Managing Task Durations

Tasks take time, they have a duration. Realistic task durations help give a realistic project end date. Aspose.Tasks allows developers to set task durations in projects.

Working with Durations

The Duration and DurationFormat properties exposed by the Tsk class are used to determine the planned duration and format of the duration of a task:

Duration in Microsoft Project

To see a task’s duration in Microsoft Project one can select More Views and then Task Entry From the View menu.

Setting task duration using Aspose.Tasks

The following examples increases and decreases the task duration to 1 week and half week respectively.

 1// Create a new project and add a new task
 2Project project = new Project();
 3Task task = project.RootTask.Children.Add("Task");
 4
 5// Task duration in days (default time unit)
 6Duration duration = task.Get(Tsk.Duration);
 7Console.WriteLine("Duration equals 1 day: {0}", duration.ToString().Equals("1 day"));
 8
 9// Convert to hours time unit
10duration = duration.Convert(TimeUnitType.Hour);
11Console.WriteLine("Duration equals 8 hrs: {0}", duration.ToString().Equals("8 hrs"));
12
13// Get wrapped TimeSpan instance
14Console.WriteLine("Duration TimeSpan equals to TimeSpan of 8 hrs: {0}", duration.TimeSpan.Equals(TimeSpan.FromHours(8)));
15
16// Increase task duration to 1 week and display if duration is updated successfully
17task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Week));
18Console.WriteLine("Duration equals 1 wk: {0}", task.Get(Tsk.Duration).ToString().Equals("1 wk"));
19
20// Decrease task duration and display if duration is updated successfully
21task.Set(Tsk.Duration, task.Get(Tsk.Duration).Subtract(0.5));
22Console.WriteLine("Duration equals 0.5 wks: {0}", task.Get(Tsk.Duration).ToString().Equals("0.5 wks"));
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.