I really can’t figure out why the instruction SELECT CONVERT(NVARCHAR(30), GETDATE(), 114) outputs, for instance,
13:04:31:997
instead of
13:04:31.997
Why is the milliseconds separator a : insted of a .? In case you need to know, I need to be able to check if a certain time is between two time values stored as XML in a table. The problem is that the separator in this table is, as it is normal for me, a ., so that using comparisons between the two formats returns wrong results because one uses . and the other uses :. Is there any way I can get the time with the . separator without using string functions like REPLACE or without changing the format stored in the table?
I think you should try to keep the format as
datetimewhen you do the comparison. In SQL Server 2008 there is a new data typetimethat would have been helpful but in SQL Server 2005 we have to usedatetimeinstead.I guess that you are using
convert(..., 114)to only get the time part from adatetimevariable. You can use this code to remove the date part and still have adatetimevariable.Result:
When you extract data from XML using
.valueyou specify the datatype to be used. If you only have the time part in the XML and you specifydatetimeyou will get the time of the date ‘1900-01-01’. So you can do the comparison usingdatetimelike this.Result: