Subtracting DateTime Data Type in SQL Server

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 23
Reputation: fayenot is an unknown quantity at this point 
Solved Threads: 0
fayenot fayenot is offline Offline
Newbie Poster

Subtracting DateTime Data Type in SQL Server

 
0
  #1
Jun 18th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 3
Reputation: StephenP is an unknown quantity at this point 
Solved Threads: 0
StephenP StephenP is offline Offline
Newbie Poster

Re: Subtracting DateTime Data Type in SQL Server

 
0
  #2
Jun 19th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: OldDude is an unknown quantity at this point 
Solved Threads: 1
OldDude's Avatar
OldDude OldDude is offline Offline
Newbie Poster

Re: Subtracting DateTime Data Type in SQL Server

 
0
  #3
Jun 19th, 2008
Try this
http://keentiger.com/2008/01/22/sql-...tween-2-dates/

or Google SQL server datediff
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 178
Reputation: sbv is an unknown quantity at this point 
Solved Threads: 8
sbv's Avatar
sbv sbv is offline Offline
Junior Poster

Re: Subtracting DateTime Data Type in SQL Server

 
0
  #4
Jun 23rd, 2008
Originally Posted by OldDude View Post
Try this
http://keentiger.com/2008/01/22/sql-...tween-2-dates/

or Google SQL server datediff
nice link. thanks.
Accept Challenges and Enjoy Coding... :)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC