Mysql date comparison problems now the table kucun contains datavalue (varchar, in the format of 2012-01-01) and price (float11, 2) now I want to obtain data FROM to. I write this method: 1. SELECT * FROM 'Ku mysql date comparison problem
Now the table kucun contains the datavalue (varchar, in the format of) and price (float) fields.
Now I want to get the data from.
1,
SELECT * FROM 'Kun' where datavalue between 'unix _ TIMESTAMP (2012-07-10) 'and 'unix _ TIMESTAMP (2012-08-10 )'
The result is null.
2,
SELECT * FROM 'Kun' WHERE datavalue BETWEEN '2017-07-10 'AND '2017-08-10'
The result is correct. I have obtained the data I want to find.
3,
SELECT * FROM 'Kun' where UNIX_TIMESTAMP (datavalue)> UNIX_TIMESTAMP (2012-07-10) and UNIX_TIMESTAMP (datavalue) The result is null.
Is 1 and 3 empty? 2 Is it formal? Can a date in a format like XXXX-XX-XX be compared?
------ Solution --------------------
1,
SELECT * FROM 'Kun' where datavalue between 'unix _ TIMESTAMP (2012-07-10) 'and 'unix _ TIMESTAMP (2012-08-10 )'
Extra quotation marks to be deleted
3,
SELECT * FROM 'Kun' where UNIX_TIMESTAMP (datavalue)> UNIX_TIMESTAMP ('2017-07-10 ') and UNIX_TIMESTAMP (datavalue) Quotation marks required
------ Solution --------------------
The string parameter of the UNIX_TIMESTAMP () function must be enclosed in quotation marks, so try:
SQL code
SELECT * FROM `kucun` where UNIX_TIMESTAMP(datavalue)>UNIX_TIMESTAMP('2012-07-10') and UNIX_TIMESTAMP(datavalue)