Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Minutes to HH:MM

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2005-01-27 : 15:38:34
What's the easiest way to cast an integer of minutes into a character string like HH:MM?

Anyway to use CONVERT? 114, 108 especially?

X002548
Not Just a Number

15586 Posts

Posted - 2005-01-27 : 16:02:10
You'd still have to convert the values if you'd want to use it as a date


DECLARE @min int
SELECT @min = 123
SELECT RIGHT('00' + CONVERT(varchar(2),@min/60),2)+ ':'
+ RIGHT('00' + CONVERT(varchar(2),CONVERT(int,((@min/60.00)-(@min/60))*60)),2)




Brett

8-)
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-01-27 : 16:24:02
I'm not sure you're a minimalist Brett...

And why isn't there a MOD or MODULO function in SQL

Thanks for the (long) answer!

Sam
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-01-27 : 16:25:48
or you could use mod (%)


DECLARE @min int
SELECT @min = 123
SELECT
RIGHT('00' + CONVERT(varchar(2),@min/60),2)+ ':'
+ RIGHT('00' + CONVERT(varchar(2),@min%60),2)


Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-01-27 : 16:26:07
danggit!



Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-01-27 : 16:28:55
or

DECLARE @min int
SELECT @min = 123

Select left(convert(varchar,dateadd(n,@min,0),108),5)


Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-01-27 : 16:30:31
Corey has some minimalist traits. And reads BOL too...
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-01-27 : 16:34:40
Do I win something ??

No... *sigh*

Corey

"If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-01-27 : 16:35:46
Well, you could join the minimalist (uh what did Brett call it? religion?)

We call ourselves: min
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-01-27 : 16:44:26
snds gd

cnt me n

Corey

"If th nly tol u hv is a hmmr, th whl wrld lks lk a nal." - Mrk Twn
Go to Top of Page
   

- Advertisement -