# Calculate Duration

Hi,

Can we calculate the duration of the task using the task start date and end date?

example ,

start date ----> 12-12-18
end date ----> 12-12-18

so Duration Should be -------> 1 day

but, You’re showing -----> 0 day !!!

Need Answer As Soon As Possible !!!

HOW TO ACCESS CALCULATE DURATION METHOD ?

I assume your duration_unit is “day” correct?

Well the duration is (at most) 23:59h which is not a full day. As the duration is given as an integer that is the expected behaviour. If the task is only scheduled to last from 15:00 to 16:00 then showing one day would be wrong wouldn’t it?

However where do you want to display the duration? Can’t you simple fake the result you want it to have? For example in the gantt bars itself you could have something like:

``````gantt.templates.task_text = (start, end, task) => {
// if the task starts and ends on the same day, it is assumed to last the whole day
if(gantt.date.date_part(start) === gantt.date.date_part(end)) {
return 1;
}
}
``````

(untested code)

See this I need ,

example ,

start date ---- 12-12-18
end date ---- 12-12-18

so Duration Should be ------- 1 day

see another example :------
example ,

start date ---- 12-12-18
end date ---- 13-12-18

so Duration Should be ------- 2 day

----------------------------------------------------------------------------------------
So is that possible ???
-----------------------------------------------------------------------------------------
Need Answer As Soon As Possible !!!

Hello,
If you don’t specify the time for the date Gantt considers it as 00:00:00. So this is how it looks in your example:

``````start date ----> 12-12-18 00:00:00
end date ----> 12-12-18 00:00:00
``````

Here is another example:

``````start date ----> 12-12-18 09:00:00
end date ----> 12-12-18 12:00:00
``````

If your duration unit is `hour`, the duration parameter will show the number of hours. And it will be 3 hours.
But if your duration unit is `day`, Gantt will round the duration and it will be 0 days.

There is no built-in solution to change the logic that is used to calculate the duration. And there are various ways how to work around it.
I think the easiest way would be to subtract 1 minute before updating a task or opening the lightbox. Here is an example:
http://snippet.dhtmlx.com/a73af08c3

We are not using time concept …
get that !!!

So tell me the exact solution without using time …

Hello,
If you don’t want to use the previous solution, here is another one:
https://snippet.dhtmlx.com/73c87bf0c

But any solution requires modifying the end_date or duration.

Update:
It is not recommended to update the task dates when it is not necessary.
There are various ways to show inclusive dates, and the following article explains how it can be done: