sql server - Convert a string to datetime -
This timestamp is saved as a string in the table How can I convert it to a datetime type while querying in the table Am I
For example:
declare @timestamp as nvarchar set @timestamp = '20130319092507.000000-000' I tried convert (datetime, timestamp, * n *) and dead (datetime as timestamp)
My first suggestion: fix your table! Stop storing date / time values in the form of a string, nothing can be better than this, for example columns may contain 20130231 or holovan or There is no date and now you have to filter those people, in addition to the underlying assumptions, you also lose the ability to perform date operations. DECLARE @timestamp VARCHAR (32); SET @timestamp = '20130319092507.000000-000'; Select convert (DATETIME, LEFT (@timestamp, 8) + '' + STUFF (STUFF (SUBSTRING (@timestamp9, 6), 3,0, ':'), 6,0, ':' '));
Comments
Post a Comment