June 2, 2011 at 7:09 am
Hi,
I have strings like this:
20110531095841 is there any function to convert this string to date , like:
2011-05-31 09:58:41
Thank you
June 2, 2011 at 8:16 am
You might use something like this to achieve what you require.
DECLARE @T VARCHAR(15)
DECLARE @X VARCHAR(20)
SET @T = '20110531095841'
SET @X = (SUBSTRING(@T,1,4)+'-'+SUBSTRING(@T,5,2)+'-'+SUBSTRING(@T,7,2)+' '
+SUBSTRING(@T,9,2)+':'+SUBSTRING(@T,11,2)+':'+SUBSTRING(@T,13,2))
SELECT CONVERT(SMALLDATETIME,@X,101)
Result: 2011-05-31 09:59:00
June 2, 2011 at 8:22 am
"If everything seems to be going well, you have obviously overlooked something"
Sorry didn't understood? what did you meant by that?
June 2, 2011 at 10:26 am
river1 (6/2/2011)
"If everything seems to be going well, you have obviously overlooked something"Sorry didn't understood? what did you meant by that?
For example, the data you supplied was "20110531095841", apparently May 31, 2011 9:58 AM. Now will June 1, 2011 be
1. 20110601 to represent June 1, 2011
Or will this
2. 2011061 represent June 1, 2011
If it is the 2nd item then the solution given obviously will not work properly.
So in effect it is a reminder to test, test and test the solution again before placing into production
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply