Declare @value nvarchar(100)= 'Generated by [email protected] on 12/5/2014 1:00:13 PM from ATOM.'
Select LEFT(REVERSE(LEFT(REVERSE(RTRIM(@value)), 31)),20)
現在男孩和女孩,所有的日期格式的解決方案,以及可變長度後綴
Declare @values table (value nvarchar(100) NOT NULL);
INSERT @values VALUES
('Generated by [email protected] on 2/2/2014 1:00:13 PM from ATOM.'),
('Generated by [email protected] on 17/2/2014 1:00:13 PM from SOmewhere.'),
('Generated by [email protected] on 2/11/2014 1:00:13 PM from NeverNeverLand.'),
('Generated by [email protected] on 12/11/2014 1:00:13 PM from X.')
SELECT
RTRIM(SUBSTRING(V.value, PATINDEX(X.Pattern, V.value)+1, X.Patlength))
FROM
@values V
JOIN
(
VALUES
('% [1-9]/[1-9]/2[0-3][0-9][0-9]%', 20),
('% [1-3][0-9]/[1-9]/2[0-3][0-9][0-9]%', 21),
('% [1-9]/1[0-2]/2[0-3][0-9][0-9]%', 21),
('% [1-3][0-9]/1[0-2]/2[0-][0-9][0-9]%', 22)
) X (Pattern, Patlength) ON PATINDEX(X.Pattern, V.value) > 0
來源
2014-12-05 13:02:50
gbn
常數也更然後61個字符... – gbn 2014-12-05 13:01:35
我真的* *會考慮使用ISO-8601的日期格式以確保每個日期和時間長度都是標準化的,並且獨立於本地設置。我是英國人,你的日期/時間格式坦白地說是無稽之談 – gbn 2014-12-05 13:26:06