Groups | Blog | Home
all groups > sql server programming > july 2006 >

sql server programming : how to convert int to time


vishwadh NO[at]SPAM gmail.com
7/16/2006 11:17:19 PM
hi

I want to know, how will we convert int to time.let me show u by
example.
if i have int i=12435 then it will convert into hours,minutes and
seconds.....
let this i will be in seconds.so how can i convert this?is there any in
built function to convert this int(seconds) into time.

thanks in advance
Ben Nevarez
7/16/2006 11:33:02 PM

Take a look at CAST and CONVERT (Transact-SQL) in Books Online.

Ben Nevarez, MCDBA, OCP
Database Administrator


[quoted text, click to view]
Erland Sommarskog
7/17/2006 12:00:00 AM
(vishwadh@gmail.com) writes:
[quoted text, click to view]

Given 12435, what do you the result to be?

If am to guess what you are looking for, I would place my bets on

SELECT convert(char(8), dateadd(ss, 12435, '19000101'), 108)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
vishwadh
7/17/2006 12:04:09 AM
I didnt able to convert it into time by using cast and convert
if u can then plz send me the code


Thanks


[quoted text, click to view]
Adi
7/17/2006 12:06:50 AM
As far as I know converting int to datetime will only show you the
date part and the hour will always be set to midnight. Maybe you are
looking for dateadd function that lets you add 12345 seconds to a
certain date?

Adi

[quoted text, click to view]
vishwadh
7/17/2006 12:12:25 AM
Actually i want to display this int or you can say seconds into time
format only.



[quoted text, click to view]
Omnibuzz
7/17/2006 12:13:02 AM
try this

declare @input int
set @input = 12435
select convert(varchar(10),dateadd(ss,@input,0),108)

--
-Omnibuzz (The SQL GC)

http://omnibuzz-sql.blogspot.com/

Adi
7/17/2006 12:27:37 AM
I'm sorry, but I don't understand what you want. Can you show me the
output that want to get from the number 12345?

Adi

[quoted text, click to view]
amish
7/17/2006 12:39:56 AM

[quoted text, click to view]

you must know start time since when this seconds you are counting.

For me in epoch time I got seconds in int format.
This seconds are counted for time since '1 Jan 1970 00:00:00'
so if we have 12345 seconds elapsed then

select dateadd(ss,12345,'1970-01-01')

it will give time 1970-01-01 03:25:45.000 means 12345 seconds after 1
Jan 1970.

Regards
Amish Shah
vishwadh
7/17/2006 1:59:46 AM
Thanks alot.I got the solution....
i used dateadd function...



[quoted text, click to view]
Aaron Bertrand [SQL Server MVP]
7/17/2006 4:52:38 AM
If you are starting with a number of seconds see
http://www.aspfaq.com/2271





[quoted text, click to view]

AddThis Social Bookmark Button