Hi
select substring('123456',1,2)+':
in your case you could use:
select substring(filedName,1,2)+'
Main Topics
Browse All TopicsHi
In SQL 2005/2008 I am getting an integer result from a msdb stored proc that is a time in big int, i.e. 173540. which is 17:35:40
how do I get 173540 (starts out a number, not given as char, so neede to convert to char first?) converted to :
5:35:40 pm
and
17:35:40
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
What about the int 12345?
DECLARE @Int INT
SET @Int = 12345
SELECT
SUBSTRING(CONVERT(VARCHAR,
SUBSTRING(CONVERT(VARCHAR,
RIGHT(CONVERT(VARCHAR, @Int), 2)
Do you just want a string representation, or do you want a variable on which you can perform time arithmetic? The reason I ask about 2005/2008 is that 2008 has a time type.
Saied + Pratima: your code will not work for early morning hours, i.e. 1:23:45 as Allister points out
Allister : yours is close, would have liked to have similar to AC's format, i.e. 01:23:45, whereas yours gives 1:23:45 which while correct in "24hr clock speak" the leading zero helps indicate is a 24hr clock, not a 12 hr clock.
Sorry, is SQL 2008 on one machine and SQL 2005 on another so trying to make code compatible. The BIG INT is supplied by :
msdb.dbo.sysjobs, field run_time
and that table has the field as big int, not a time format unfortunately
AC: thanks, first part of question answered. That is exact format I need for 24hr.
And second part of question, how do I get into :
5:35:40 pm
format ?
>>msdb.dbo.sysjobs, field run_time
and that table has the field as big int, not a time format unfortunately<<
The sysjobs does not contain a run_time column. There is a run_time column in the sysjobhistory, but it is an int not a bigint.
In any case to answer your question you can do this:
DECLARE @X bigint
SET @X = 173540
SELECT RIGHT(CONVERT(varchar(19),
If you also need seconds, then you are going to have to get more creative and do something like this:
SELECT STUFF(RIGHT(CONVERT(varcha
Business Accounts
Answer for Membership
by: Allister_ReidPosted on 2009-11-06 at 01:47:28ID: 25757818
Hi,
which is it? SQL Server 2005 or 2008?
Regards