| | |
Subtracting DateTime Data Type in SQL Server
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 23
Reputation:
Solved Threads: 0
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
•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Solved Threads: 0
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
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.
•
•
•
•
Try this
http://keentiger.com/2008/01/22/sql-...tween-2-dates/
or Google SQL server datediff
Accept Challenges and Enjoy Coding... :)
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: http error 404
- Next Thread: Need information about winDNA
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





