Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8095735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:13:59+00:00 2026-06-05T21:13:59+00:00

I have a stored procedure which update a table based on such calculation and

  • 0

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.

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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:14:01+00:00Added an answer on June 5, 2026 at 9:14 pm

    You can just use style 108 instead of 114 in the CONVERT function to get only the hh:mm:ss:

    CREATE PROCEDURE dbo.St_Proc_UpdateTimeSpent        
         @timeEntryID int,        
         @status int output        
    AS BEGIN
       SET NOCOUNT ON;
    
       DECLARE @Date DATETIME;
       SET @Date = GETDATE(); 
    
       UPDATE dbo.Production 
       SET TimeSpent = CONVERT(VARCHAR(20), DATEADD(SS, DATEDIFF(ss, CalendarDate, @Date)%(60*60*24),0), 108),  
           IsTaskCompleted = 1
       WHERE  
           productionTimeEntryID = @timeEntryID         
    
       SET @status = 1;
    
       RETURN @status;        
    END
    

    See the excellent MSDN documentation on CAST and CONVERT for a comprehensive list of all supported styles when converting DATETIME to VARCHAR (and back)

    BTW: SQL Server 2008 also introduced a TIME datatype which would probably be a better fit than a VARCHAR to store your TimeSpent values … check it out!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure which is called inside a trigger on Insert/Update/Delete. The
I have created one stored procedure which runs on 5000 users in tbluser table
I have a stored procedure which filters based on the result of the DATEADD
I have a stored procedure which takes an XML parameter and inserts the data
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I have a stored procedure which basically does something like select top 1 expiryDate,
I have a stored procedure which is doing a lot of delete. Hundreds of
I have a stored procedure which executes another procedure inside it. The second one
I have a messy stored procedure which uses dynamic sql. I can debug it
I have a stored procedure in which i want to create a user defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.