Project server defines the duration as
The total span for working time for a task or project
The working time
here depend on the current project server calendar settings.
So if you configured your calendar to have two days as weekends let's say Saturday & Sunday with 8 hours per day and you have a task that starts on Saturday and ends on Tuesday so the duration should be 2 days
as working time and not 4 days
.
So regarding your issue if you tried to use DateDiff
function you will get the difference between the end date and start date that based on my above example is should be 4 not 2 like duration field value.
But if you need to calculate only working time depending on your calendar setting so in this case, you should use ProjDateDiff( date1, date2, calendar )
instead of DateDiff
.
the ProjDateDiff
will calculate the date difference between two dates based on the project server calendar settings.