Click here to Skip to main content
12,405,088 members (66,332 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL Server
hi am using sqlserver 2005. i hv a table in which 5 columns are there Start_time, pause_time, continue_time, pause_duration, end_time and total_duration. when i clicked on pause_time and continue_time the time difference should be displayed in pause_duration column for that i hv written the code. the thing is when i clicked on pause_time and continue_time the differnce should be added to the previous result for that what i need to do?

pls help...
thankks in advance,
Posted 22-Jan-13 22:40pm
Comments
CHill60 23-Jan-13 4:53am
   
What do you mean by "added to the previous result" ? Do you mean total_duration?
in C# total_duration += difference
in SQL Update [table] set total_duration = total_duration + difference where ...
brinda f5 23-Jan-13 5:07am
   
1st time when i clicked on pause_time and continue_time the difference should be inserted in pause_duration column and 2nd time when i clicked on pause_time and continue_time the difference should be added to the previous value in pause_duration column.
brinda f5 23-Jan-13 5:24am
   
no every thing should be inserted in 1 row itself
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

in C# pause_duration += difference
in SQL Update query set pause_duration = pause_duration + difference

and if you are storing in SQL the pause time and continue time in different rows then the pause duration will be the some for that unique id
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

First calculate the time difference and store it. Then when a new difference is calculated just add that to the previous value.

//The first time it is null when initializing.
PauseDuration = null;
 
//Then every time for calculation
PauseDuration += ContinueTime - PauseTime;
  Permalink  
Comments
brinda f5 23-Jan-13 23:20pm
   
which datatypes i hv to take for pauseduration,continuetime and pausetime
shiny13 23-Jan-13 23:41pm
   
Initialize the variables ContinueTime and PauseTime as DateTime. Everytime you subtract two DateTime variables the out is generated in TimeStamp, so you can initialize PauseDuration as Timestamp. A TimeStamp variable can be converted to string if you want to display it. By default it is in this format: "hh:mm:ss:nn" where hh is hour, mm is minute, ss is second and nn is nano second or microsecond (not exactly sure but could be either).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100