如何从字符串中分离日期? [英] How to separate date from a string?

查看:28
本文介绍了如何从字符串中分离日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的字符串,

在 01-15-09,因子为 0.8"

"on 01-15-09 witha factor of 0.8"

我想以下面的方式分离这个字符串,

i wanted to seperate this string in the follwing way,

1] 日期为 01-15-092] 系数 0.8

1] date as 01-15-09 2] Factor of 0.8

注意:字符串长度不固定.

NOTE : String length is not fixed.

那么我们如何以#1 & 的形式分离数据?#2 ?

so how can we seperate the data in the form of #1 & #2 ?

推荐答案

要获取日期,您可以使用 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)

这篇关于如何从字符串中分离日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆