Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a stored procedure which update a table based on such calculation and the calculation is done as Column Name (Calendatedate) -( Current System Date Time) and update this information to a column (TimeSpent) and display the value in Hh:Mm:SS:Msec Format. The Query is working fine but i want to update it in such a way so that the Time spent should be only HH:MM:SS Format.Please help me that how i remove that Msec From the time Spent.


SQL
CREATE procedure St_Proc_UpdateTimeSpent        
@timeEntryID int,        
@status int output        
as begin         
set nocount on;        
declare @Date dateTime;        
set @Date=GETDATE(); 
	update Production set TimeSpent=(SELECT CONVERT(VARCHAR(20),DateAdd(SS,Datediff(ss,CalendarDate, @Date)%(60*60*24),0),114)),  
	IsTaskCompleted=1       
	where productionTimeEntryID=@timeEntryID         
	set @status=1;        
	return @status;        
end
Posted

1 solution

Try 108 instead of 114 in the CONVERT function to get only the hh:mm:ss format.

Refer: MSDN: CAST and CONVERT (Transact-SQL)[^]
 
Share this answer
 
Comments
Dharmenrda Kumar Singh 20-Jun-12 1:18am    
Thanks ...
Sandeep Mewara 21-Jun-12 16:51pm    
Welcome.
Developer29 17-May-17 1:03am    
This is query is working but I want to make sum of this time....How to calculate sum of hh:mm:ss

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900