Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Display negative seconds in HH:MM:SS format Expand / Collapse
Author
Message
Posted Monday, July 28, 2014 8:55 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 6:35 AM
Points: 18, 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.
Post #1596904
Posted Monday, July 28, 2014 9:09 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:55 PM
Points: 4,046, Visits: 9,200
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.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1596913
Posted Wednesday, July 30, 2014 6:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 6:35 AM
Points: 18, 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.
Post #1597677
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse