Sybase: Convert seconds to a human readable duration

Let’s say you get a number of seconds and want to convert it to a string so that it’s human readable e.g. saying that something took 15157 seconds is probably not a good idea and it’d make more sense to say it took 4 hours 12 minutes and 37 seconds.

Here’s a very simple stored procedure to perform this conversion:

create procedure hours_min_sec(@seconds int)
select right('00'+convert(varchar(2), floor(@seconds / 3600)), 2)+':'+right('00'+convert(varchar(2),floor(@seconds / 60) % 60), 2)+':'+right('00'+convert(varchar(2),@seconds % 60), 2)

Note that the you may see a line wrap here but actually everything after begin and before end should be on one line.

You can use it like this:

1> hours_min_sec 15157
2> go


(1 row affected)
(return status = 0)

One thought on “Sybase: Convert seconds to a human readable duration

  1. Hello Henri,

    can you please let me know, how to find the unused stored procedures using monitoring tables of master database in sybase.

    actually, i already wrote 2 different stored procedures using monitoring tables to find the unused indexes and tables using monopenObjectactivity table. and those stored procedures are running in production to capture the data for around 2 months and then later i will write a query on permanant table which i created as part of stored proc to save the historical data and get the unused objects and indexes.

    In the same way i need to create the stored procedure to monitor the historical data for unused stored procedures in the server and monitor the stored procedures for 2 production releases and then if those stored procs are never used from past 4 to 5 months in production then i need to drop them. This is my task.

    can you please suggest me how do i write a stored procedure to monitor the unused stored procs and save the data to one permanant table and that should stored proc which i write dba’s would schedule it to run on daily basis to gather the historical data. then i need to query the permanant table and list all the unused stored procedures. so that the developers would review them and decide whetther to really drop those stored procedure or not……

    please expert, give me the query but please don’t give me the links, as i have already googled and i’m unable to find a way…

    this above pdf has the query for analyzing the stored procedure performance queries…by considering these information , can you please suggest me?

    Thanks alot in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *