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?
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.
You can convert to DATE
and TIME(0)
.
CONVERT(DATE, [timeStamp]) AS date, CONVERT(TIME(0), [timeStamp]) AS time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With