943,522 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 14400
  • ASP.NET RSS
Jun 18th, 2008
0

Subtracting DateTime Data Type in SQL Server

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fayenot is offline Offline
23 posts
since May 2008
Jun 19th, 2008
0

Re: Subtracting DateTime Data Type in SQL Server

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,
Stephen
Last edited by StephenP; Jun 19th, 2008 at 1:00 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
StephenP is offline Offline
3 posts
since Jun 2008
Jun 19th, 2008
0

Re: Subtracting DateTime Data Type in SQL Server

Try this
http://keentiger.com/2008/01/22/sql-...tween-2-dates/

or Google SQL server datediff
Reputation Points: 10
Solved Threads: 1
Newbie Poster
OldDude is offline Offline
8 posts
since Mar 2008
Jun 23rd, 2008
0

Re: Subtracting DateTime Data Type in SQL Server

Click to Expand / Collapse  Quote originally posted by OldDude ...
Try this
http://keentiger.com/2008/01/22/sql-...tween-2-dates/

or Google SQL server datediff
nice link. thanks.
sbv
Reputation Points: 15
Solved Threads: 8
Junior Poster
sbv is offline Offline
178 posts
since Jan 2008
Jul 24th, 2010
0

re subtract time

select convert(varchar(10), Time2-Time1, 108)from tbl
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sandeep.pande is offline Offline
1 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: help for asp.net project
Next Thread in ASP.NET Forum Timeline: button in asp:repeater not worked





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC