简体   繁体   English

Substring_Index到Date

[英]Substring_Index to Date

I have problem,, so i have table let said name is table1, that table1 have filed name UserName. 我有问题,所以我有表让所说的名字是table1,那个table1已经归档了UserName。 And the value like this " Jiyo-192.168.10.22 Date 31-Aug-2016 Jam 11:35:36 ", so the format value like this &Name&-&ipaddress& Date &datetime& . 而像这样的价值“ Jiyo-192.168.10.22 Date 31-Aug-2016 Jam 11:35:36 ”,所以格式值如此&Name& - &ipaddress&Date&datetime& Cause i wanna UserName became date i use subtring_index like this SUBSTRING_INDEX(SUBSTRING_INDEX(UserName,'Date ',-1),' Jam',1) AS date1 But my problem is i need query where date1 between two date, i just use my code like this 因为我想UserName成为日期我使用subtring_index像这样SUBSTRING_INDEX(SUBSTRING_INDEX(用户名,'日期',-1),'果酱',1)AS date1但我的问题是我需要查询两个日期之间的date1,我只是使用我的像这样的代码

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(UserName,'Date ',-1),' Jam',1) FROM table1 
WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(UserName,'Date ',-1),' Jam',1) BETWEEN DATE_FORMAT('2016-11-01','%d-%b-%Y') AND DATE_FORMAT('2016-11-18','%d-%b-%Y')

But is not wokring the result showing from 12-Mar-2007 until 17-Nov-2016. 但是,从2007年3月12日到2016年11月17日,我们的结果并不令人满意。 Did i get something wrong or substring_index really not working to get value date?? 我得到了什么错误或substring_index真的没有工作来获得价值日期?

I think you have to use CAST() to perform a BETWEEN like that: 我认为你必须使用CAST()来执行BETWEEN

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(UserName,'Date ',-1),' Jam',1) FROM table1 
  WHERE SUBSTRING_INDEX(SUBSTRING_INDEX(UserName,'Date ',-1),' Jam',1)
    BETWEEN CAST('2016-11-01' AS DATETIME)
      AND CAST('2016-11-18' AS DATETIME)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM