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.
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...
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
... 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.
is pronounced ree-bar and is a Modenism for R
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. Helpful Links:
How to post code problemsHow to post performance problemsForum FAQs