SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Display negative seconds in HH:MM:SS format


Display negative seconds in HH:MM:SS format

Author
Message
justfillingtime
justfillingtime
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 77
I'm calculating the difference between two text boxes which record the time in seconds. When I get negative results EG -223 seconds, how can I display this as -00:03:43?

Cheers.
Luis Cazares
Luis Cazares
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41768 Visits: 19815
Didn't realize that this was for reporting services until I was posting. Maybe this T-SQL code might give you an idea.

DECLARE @Seconds int = -223
SELECT CASE WHEN @Seconds < 0 THEN '-' ELSE '' END +
RIGHT( '0' + CAST( ABS( @Seconds / 3600) AS VARCHAR(2)), 2) + ':' +
RIGHT( '0' + CAST( ABS( (@Seconds % 3600) / 60) AS VARCHAR(2)), 2) + ':' +
RIGHT( '0' + CAST( ABS( (@Seconds % 3600) % 60) AS VARCHAR(2)), 2)




Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
justfillingtime
justfillingtime
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 77
Thanks for that. I can use that in my SQL script to get the result and display from their. Saves messing about in Reporting Services.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search