如何从MySQL中的字符串中提取日期?
要从MySQL中的字符串中提取日期,请使用SUBSTRING_INDEX()。让我们首先创建一个表-
create table DemoTable -> ( -> Title text -> );
使用插入命令在表中插入一些记录-
insert into DemoTable values('John has got joining date.12/31/2018');
insert into DemoTable values('Carol has got joining date.01/11/2019');
insert into DemoTable values('Sam will arrive at.12/03/2050');使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+---------------------------------------+ | Title | +---------------------------------------+ | John has got joining date.12/31/2018 | | Carol has got joining date.01/11/2019 | | Sam will arrive at.12/03/2050 | +---------------------------------------+ 3 rows in set (0.00 sec)
这是从MySQL中的字符串中提取日期的查询-
select substring_index(substring_index(Title,".", -1), ".", 1) from DemoTable;
这将产生以下输出-
+----------------------------------------------------------+ | substring_index(substring_index(Title,".", -1), ".", 1) | +----------------------------------------------------------+ | 12/31/2018 | | 01/11/2019 | | 12/03/2050 | +----------------------------------------------------------+ 3 rows in set (0.00 sec)
热门推荐
10 祝福语短句简短好听霸气
11 朋友生闺女简短祝福语
12 接亲祝福语简短10字
13 新年孕妈祝福语简短
14 年底了祝福语简短的
15 社团迎新祝福语简短英语
16 生日祝福语 简短独特情话
17 公司最好的祝福语简短
18 结婚祝福语 暖心简短