开发者

Using STR_to_DATE in PHP SQL Query

开发者 https://www.devze.com 2023-02-07 13:58 出处:网络
I need a way of changing the format the date format from datetime to just the date in an SQL qu开发者_StackOverflowery, I have tried:

I need a way of changing the format the date format from datetime to just the date in an SQL qu开发者_StackOverflowery, I have tried:

$sql="SELECT created_by FROM meetings WHERE STR_TO_DATE('date_start', 'Y-m-d')='$CorrectDate'";

but to no avail.

date_start is the field in the SQL table.

Any help welcome!!!


SELECT  created_by
FROM    meetings
WHERE   date_start >= $correctDate
        AND date_start < $correctDate + INTERVAL 1 DAY

Unlike any solution which involves a function or an expression over date_start, this one is sargable, i. e. able to use an index on date_start efficiently.

0

精彩评论

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