Converting Varchar Seconds to Minutes:Seconds Format

Converting Varchar Seconds to Minutes:Seconds Format

Post by William Rya » Wed, 23 Oct 2002 05:43:22



I am going NUTS.  I have a value, for instance 247 that's
stored as an integer.  Anyway, I need my query to format
it in Minutes/Second format....

What I want to do is essentially Concatenate
(Job_Length/60) & (Job_Length%60)

I keep getting this error:

Syntax error converting the varchar value ':' to a column
of data type int.

Here's my query in it's entirety...ANd I've tried Casting
every way imagineable (except probably the right way).  
Any help is seriously appreciated:

SELECT Department, Work_Type, Job_Number
        , Author_ID, Author_Name, Author_Date
        , Author_Time, Patient_SSN, (Job_Length  / 60)  
+':' +(Job_Length %60) as 'Job Length'
FROM Tbl_Job_Tracking Where Job_Number = '979075'

 
 
 

Converting Varchar Seconds to Minutes:Seconds Format

Post by Aaron Bertrand [MVP » Wed, 23 Oct 2002 05:48:11


Quote:> SELECT Department, Work_Type, Job_Number
> , Author_ID, Author_Name, Author_Date
> , Author_Time, Patient_SSN, (Job_Length  / 60)
> +':' +(Job_Length %60) as 'Job Length'
> FROM Tbl_Job_Tracking Where Job_Number = '979075'

Try

SELECT ... , CAST(Job_Length / 60 AS VARCHAR) + ':' + CAST(Job_Length % 60
AS VARCHAR(2)) ...

 
 
 

Converting Varchar Seconds to Minutes:Seconds Format

Post by Dinesh.T.K » Wed, 23 Oct 2002 05:56:18


William,

SELECT CONVERT( varchar , DATEADD( second , 247 , '' ) , 108 ) as 'hh:mm:ss'

Dinesh, SQL Server MVP
--
--
SQL Server FAQ at
http://www.tkdinesh.com


Quote:> I am going NUTS.  I have a value, for instance 247 that's
> stored as an integer.  Anyway, I need my query to format
> it in Minutes/Second format....

> What I want to do is essentially Concatenate
> (Job_Length/60) & (Job_Length%60)

> I keep getting this error:

> Syntax error converting the varchar value ':' to a column
> of data type int.

> Here's my query in it's entirety...ANd I've tried Casting
> every way imagineable (except probably the right way).
> Any help is seriously appreciated:

> SELECT Department, Work_Type, Job_Number
> , Author_ID, Author_Name, Author_Date
> , Author_Time, Patient_SSN, (Job_Length  / 60)
> +':' +(Job_Length %60) as 'Job Length'
> FROM Tbl_Job_Tracking Where Job_Number = '979075'

 
 
 

1. Changing format from seconds to hours:minutes:seconds

Hello

This regards SQL Server 7.0
I have a column in a table that stores seconds.
So when i access the table i see different amounts of
seconds.
Is there a easy way to format this when accessing the
table to see this in hours:minutes:seconds

Now i write:
Select id, seconds from TableA

And get the result:
ID          Seconds
1           76123
2           4342
3           956345

But what would like to see is:
ID          Seconds
1           21:08:43
2           01:12:22
3           265:39:05

So is there a convert way to this?!?
Cant create userdefined functions in SQL Server 7.0 or can
I?

Please help me out.

/Risun

2. Print from multiple layouts in one script

3. Converting seconds to hour:minutes:seconds

4. New to SQL 6.5

5. Converting minutes to minutes:seconds

6. WWW SQL Database

7. Seconds convert into Minutes

8. varchar

9. Returning a date in a 24 hour format with Hours and Minutes, no seconds

10. Convert varchar into seconds

11. How to convert a number of seconds (int) into a time format 00:00:00 (H:M:S)

12. Convert int seconds to time format

13. convert integer second to time format?