Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Time in SQL not to have millisecond

I have a datetime column in my table but I need to separate it into date and time so here's what I've done so far.

CONVERT(VARCHAR(10), [timeStamp], 103) AS date, CONVERT(TIME, [timestamp]) AS time

But the problem is, I'm having milliseconds in the time column (eg. 23:39:55.0000000) so how can I do to have just hour:minute:second only?

like image 810
Ye Myat Aung Avatar asked Oct 05 '12 09:10

Ye Myat Aung


People also ask

How can remove seconds and milliseconds from DateTime in SQL?

Given below are the two methods that we can use to remove milliseconds and seconds from datetime. METHOD 1 : In this method, we will use Convert function to convert date time to varchar and then remove the seconds and milliseconds from it and then convert it back to datetime.


1 Answers

You can convert to DATE and TIME(0).

CONVERT(DATE, [timeStamp]) AS date, CONVERT(TIME(0), [timeStamp]) AS time
like image 161
Mikael Eriksson Avatar answered Oct 29 '22 22:10

Mikael Eriksson