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.
| Author |
Topic |
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2011-06-16 : 08:56:40
|
| I have the coding from a question prior that was from a decimal 6,0 to time. BUt I havent figured the proper math to get it to work for a 4,0The field is TIME1CONVERT(VARCHAR (8),(CAST(DATEADD(SECOND, FLOOR(Time1/ 10000) * 3600 + FLOOR(Time1 / 100) % 100 * 60 + Time1 % 100, 0) AS DATETIME)) ,108)With this field... Time1 Currently is 2152This code translates to 00:21:52 It should show 21:52:00 Any help would be greatly appriciated |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-06-16 : 09:04:20
|
declare @Time1 decimal(4,0)set @Time1 = 2152selectCONVERT(VARCHAR (8),(CAST(DATEADD(SECOND, FLOOR(@Time1/ 100) * 3600 + FLOOR(@Time1) % 100 * 60 , 0) AS DATETIME)) ,108) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2011-06-16 : 09:07:21
|
| webfred,That did it.... Thank you very much. I think that's the fastest responce I've ever recieved on here ! |
 |
|
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2011-06-16 : 10:12:16
|
| Sorry Webfred one more question please. I want to also translate it into a date timeNow that the time works greatI have this... it's close but not quite right DATEADD(HOUR, FLOOR( Time1/ 100), DATEADD(MINUTE, FLOOR( Time1/ 1) % 100, DATEADD(SECOND, Time1 % 100, Date1)))Date Should = 2011-06-05Time should = 01:16:00togeather should be 2011-06-05 01:16:00.000I come back with 2011-06-05 02:32:16.000It seems like it works most of the time but sometimes it misses. |
 |
|
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2011-06-16 : 11:04:55
|
| I'm not sure if this is the best way but it seems to workCAST( Date1 + CONVERT(VARCHAR (8),(CAST(DATEADD(SECOND, FLOOR(Time1/ 100) * 3600 + FLOOR(Time1) % 100 * 60 , 0) AS DATETIME)) ,108) AS DATETIME) |
 |
|
|
Exgliderpilot
Starting Member
14 Posts |
Posted - 2011-06-17 : 04:36:29
|
| this is not quite what you want but it has produced the correct answeres for years nowSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCreate function [dbo].[af_CastMinsAsTimeString] (@ParamMins smallint)RETURNS Varchar(5)ASBEGIN DECLARE @TimeString varchar(5) DECLARE @StartHour smallint DECLARE @StartMin smallint SET @StartHour = @ParamMins / 60 SET @StartMin = @ParamMins % 60 SET @TimeString = CASE WHEN @StartHour < 10 THEN ' ' + CAST(@StartHour As Char(1)) ELSE CAST(@StartHour As Char(2)) END + ':' + CASE WHEN @StartMin < 10 THEN '0' + CAST(@StartMin As Char(1)) ELSE CAST(@StartMin As Char(2)) END RETURN @TimeStringENDGOI'm sure its easy to extend to your exact requirmentsStaff bank ageny software http:\\www.ava.co.ukBloghttp://creamteadiet.blogspot.com/ |
 |
|
|
|
|
|
|
|