I have a table for projects, it has two fields for project_start and project_end both have datetime data type. what should i do so that when the user insert dates on both field it will automatically subtract and place the answer on the duration field... please help.. oh before i forgot, the textbox for the fields are located in a formview...how can i subtract project_start and project_end and put its difference to duration field

8 Years
Discussion Span
Last Post by sandeep.pande

You can try using DATEDIFF, I think it's built into MS SQL. It's not terribly accurate though, in terms of defining boundaries between days, months, years, so you have to tweak around with it a bit - for each unit (seconds, minutes), you have to divide the value it returns, then put them together again.

For example:
take your:
x = DATEDIFF(@project_start, @project_end);

seconds = x / 60;
minutes = (x / 60) / 60;
And so on.

Hope I helped,

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.