## converting milliseconds

 Author Message ramu4ind Old Hand Group: General Forum Members Points: 393 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 SSCertifiable Group: General Forum Members Points: 5708 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 kumarkshitij@krayknot.comwww.krayknot.com ChiragNS SSCoach Group: General Forum Members Points: 17533 Visits: 1865 krayknot your answer is not complete. "Keep Trying" Samuel Vella SSCertifiable Group: General Forum Members Points: 5499 Visits: 2144 declare @milli as intset @milli = 11202079select @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 SSCrazy Group: General Forum Members Points: 2851 Visits: 417 DECLARE @ms AS INTEGERSELECT @ms = 86399998SELECT 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 Mr or Mrs. 500 Group: General Forum Members Points: 509 Visits: 281 Going back to school`declare @MILI bigintset @mili= 1*60*60*1000+2010select @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 SSC Guru Group: General Forum Members Points: 621151 Visits: 45256 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,RamuHeh... 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 ModenRBAR 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.If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair Helpful Links:How to post code problemsHow to post performance problemsForum FAQs chris.rogers00 SSChasing Mays Group: General Forum Members Points: 646 Visits: 187 CONVERT(TIME,DATEADD (ms, @YOURMILLISECONDS, 0)) Ninja's_RGR'us SSC Guru Group: General Forum Members Points: 187992 Visits: 9672 chris.rogers00 (5/13/2011)CONVERT(TIME,DATEADD (ms, @YOURMILLISECONDS, 0))This is sql 2k5, time is not available. chris.rogers00 SSChasing Mays Group: General Forum Members Points: 646 Visits: 187 gutted, sorry.. Should have read the post..