Home > Back-end >  The date format string type yy - mm - dd this how fuzzy query
The date format string type yy - mm - dd this how fuzzy query

Time:11-27

But also have to limit the month and year is the time

Select * from ` caseandcustomer ` where cname like '% a %' and cgettime like '% 2020-08 - %'

Use the SQL statement, a data but look not to come out, cgettime is varchar type

CodePudding user response:

First of all, you want to make sure that a list of all of the time data format is consistent, consistent left directly (replace (cgetime, "-", ""), 6) & gt;=202008 if you don't agree, first turn to the left (DATE_FORMAT (cgettime, '% Y % m % d'), 6) & gt;=202008

CodePudding user response:

In the front of the '%' 2020-08% % and 2020 is a blank space? How do you save the information in the database is? % of fuzzy query on behalf of any character, so the '%' is equivalent to 2020-08% 'any character + space + + any character in the 2020-08', your database is stored like this?

CodePudding user response:

reference 1st floor LikeWatchStar response:
first of all, you want to make sure that a list of all of the time data format is consistent, consistent left directly (replace (cgetime, "-", ""), 6) & gt;=202008 if you don't agree, first turn to the left (DATE_FORMAT (cgettime, '% Y % m % d'), 6) & gt;=202008


The great god, I this is to do with the current time, data in accordance with the current time yyyy - mm, according to don't agree, don't show how to do

CodePudding user response:

Alternatively, do you want to query yyyy - mm in record, you can query date meet & gt;=1 and that month & lt; Next month 1 record, SQL can change the following
 
Select * from ` caseandcustomer ` where cgettime & gt;='2020-08-01' and cgettime & lt; '2020-09-01' and cname like '% a %'

CodePudding user response:

The format into and database is not good

CodePudding user response:

Can put the time into the string in the database, and then fuzzy query the string

SELECT * FROM (SELECT left (DATE_FORMAT (cgettime, '% Y % m % d'), 6) AS cgettime FROM ` caseandcustomer `) AS t WHERE tc gettime LIKE '20%'

So try
  • Related