开发者

compare string to date on mysql

In MySQL 4.0.21-standard, I have a table with a date, saved as a string.

I want to compare this string with a date in my request.

SELECT FE_CLIENT.*
FROM FE_CLIENT
WHERE D_DATFI开发者_如何转开发NPUBLI < '2010/06/03'

How can I cast my column date_deb to a date for compare?


Assuming MySQL (if not, retag your question)

Use the MySQL STR_TO_DATE function to put the '2010/06/03' to a DATETIME value.

SELECT FE_CLIENT.*
FROM FE_CLIENT
WHERE D_DATFINPUBLI < STR_TO_DATE('2010/06/03','%Y/%m,%d');

Do the same thing for D_DATFINPUBLI if it's not already a DATETIME format.

EDIT:

SELECT STR_TO_DATE( D_DATFINPUBLI, '%d/%m/%Y %h:%i' ) DD, FE_CLIENT . * 
FROM FE_CLIENT
WHERE STR_TO_DATE( D_DATFINPUBLI, '%d/%m/%Y %h:%i' ) < STR_TO_DATE( '04/06/2010', '%d/%m/%Y' ) 
AND D_CDSTATUPUBLI <> 'EXP'
ORDER BY D_NIDPUBLI


Just format your string to proper format before query execution

or, if you want it strictly with mysql,

WHERE D_DATFINPUBLI < replace('2010/06/03','/','-')

EDIT:

D_DATFINPUBLI field must be of date type and have format of 2010-06-03

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜