开发者

getting all chars before space in SQL SERVER

开发者 https://www.devze.com 2023-01-12 03:04 出处:网络
i am trying to get all chars before the space: SUBSTRING(reporttime,1,CHARINDEX(reporttime,\' \',1)) but it is not workin开发者_JAVA百科g. please help!

i am trying to get all chars before the space:

SUBSTRING(reporttime,1,CHARINDEX(reporttime,' ',1))

but it is not workin开发者_JAVA百科g. please help!

example data:

7/8/2010 11:47 AM
7/8/2010 10:55 AM


Select Substring( MyTextColumn, 1, CharIndex( ' ', MyTextColumn ) - 1)

Actually, if these are datetime values, then there is a better way:

Select Cast(DateDiff(d, 0, MyDateColumn) As datetime)


To get the Date from a DateTime value, the best line of code I've found to strip the time value & modified to your requirements is:

CONVERT(NVARCHAR(10), reporttime, 103)

This will display 07/08/2010.

0

精彩评论

暂无评论...
验证码 换一张
取 消