且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从字符串中分离日期?

更新时间:2023-02-19 12:48:26

要获取日期,您可以使用 PATINDEX().

To get the date you can use PATINDEX().

declare @yourString varchar(100)
set @yourString = 'on 01-15-09 with a factor of 0.8'

select substring(@yourString,
            patindex('%[0-9][0-9]-[0-9][0-9]-[0-9][0-9]%', @yourString),
            8)

要获得xx 因子",您可以执行以下操作:

To get "factor of xx" you can do:

select substring(@yourString,
        patindex('%with a%', @yourString) + 7,
        20)