Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


converting milliseconds


converting milliseconds

Author
Message
ramu4ind
ramu4ind
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 200
Hi,

how to convert milliseconds into hours,minutes,seconds and milliseconds.

i have two dates from that i have taken milli seconds using datediff.now i want to display total hours,minutes,sec,millisec in that milli seconds.


Thanks,
Ramu
krayknot
krayknot
Old Hand
Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)Old Hand (348 reputation)

Group: General Forum Members
Points: 348 Visits: 534
ramu4ind (2/25/2009)
Hi,

how to convert milliseconds into hours,minutes,seconds and milliseconds.

i have two dates from that i have taken milli seconds using datediff.now i want to display total hours,minutes,sec,millisec in that milli seconds.


For calculating the time difference, directly subtract two dates from each other as



Thanks,
Ramu


kshitij kumar
kshitij@krayknot.com
www.krayknot.com
ChiragNS
ChiragNS
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2409 Visits: 1865
krayknot

your answer is not complete.

"Keep Trying"
Samuel Vella
Samuel Vella
Old Hand
Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)

Group: General Forum Members
Points: 393 Visits: 2141
declare @milli as int
set @milli = 11202079

select @milli/3600000 as hours,
(@milli - ((@milli/3600000)*3600000))/60000 as minutes,
(@milli - (((@milli)/60000)*60000)) /1000 as seconds,
@milli-(((@milli)/1000)*1000) as milliseconds
Andy Reilly
Andy Reilly
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1234 Visits: 384
DECLARE @ms AS INTEGER
SELECT @ms = 86399998

SELECT CONVERT (CHAR(13), DATEADD (ms, @ms, '01/01/00'), 14)

Obviously this would be the maximum number that it would show after this you would need to handle days - Remember that milliseconds are displayed and rounded to 1/300 of a second
JohnSmith001
JohnSmith001
SSC Journeyman
SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)SSC Journeyman (75 reputation)

Group: General Forum Members
Points: 75 Visits: 281
Going back to school


declare @MILI bigint
set @mili= 1*60*60*1000+2010

select @mili
,@Mili/(1000*60*60) as Hour
,(@Mili%(1000*60*60))/(1000*60)as Minutes
,((@Mili%(1000*60*60))%(1000*60))/1000 as Seconds
,((@Mili%(1000*60*60))%(1000*60))%1000 as MiliSecs



John Smith
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45074 Visits: 39908
ramu4ind (2/25/2009)
Hi,

how to convert milliseconds into hours,minutes,seconds and milliseconds.

i have two dates from that i have taken milli seconds using datediff.now i want to display total hours,minutes,sec,millisec in that milli seconds.


Thanks,
Ramu


Heh... lemme ask why you want to do this? Is it for display purposes? If so, then the following will probably do with the understanding that this one only goes up to 24 hours... and there's no need to convert it to milliseconds...

SELECT CONVERT(CHAR(12),@EndDate-@StartDate,114)

If you need more than 24 hours, then the following will do...
SELECT CONVERT(VARCHAR(10),DATEDIFF(hh,0,@EndDate-@StartDate)) --Converts the hours
+RIGHT(CONVERT(CHAR(8),@EndDate-@StartDate,108),6) --Converts mins & secs
AS [HHHHH:MM:SS]

... but, I have to tell you, unless it's for output to a file, you shouldn't do this type of formatting in T-SQL... especially breaking it into separate columns. Certainly, you shouldn't store the data that way. If you need to store the difference in a table, store it as a DateTime datatype... that way, you can add them up later on and display the total either in a GUI or using one of the other conversion methods on this thread for the display.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
chris.rogers00
chris.rogers00
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 187
CONVERT(TIME,DATEADD (ms, @YOURMILLISECONDS, 0))
Ninja's_RGR'us
Ninja's_RGR'us
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20931 Visits: 9671
chris.rogers00 (5/13/2011)
CONVERT(TIME,DATEADD (ms, @YOURMILLISECONDS, 0))


This is sql 2k5, time is not available.
chris.rogers00
chris.rogers00
SSC Journeyman
SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)SSC Journeyman (78 reputation)

Group: General Forum Members
Points: 78 Visits: 187
gutted, sorry.. Should have read the post..

Wink
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search