MySQL where STR_TO_DATE >= now

date, mysql, where-clause

Solution

This expression `STR_TO_DATE('datum', '%m-%d-%Y')` returns `NULL` because the column name was quoted using single quote. It doesn't convert the `value` of column `datum` but string `datum` is converted that is why it results to a `NULL` value.

To fix, just remove the single quotes around the column name.

SELECT * 
FROM Diensten 
WHERE STR_TO_DATE(datum, '%d-%m-%Y') >= CURDATE()
ORDER BY STR_TO_DATE(datum, '%d-%m-%Y') ASC

- MySQL - when to use single quotes, double quotes, and backticks?

Problem

I want to get records from the MySQL database with date today or later. The data is recorded into the database as VARCHAR (fieldname datum), so I need to use STR_TO_DATE. However, this query is not working: ``` SELECT * FROM Diensten WHERE STR_TO_DATE('datum', '%m-%d-%Y') >= DATE(NOW()) ORDER BY STR_TO_DATE('datum', '%m-%d-%Y') ASC ``` I also tried CURDATE(), doesn't work either. The query is working without the WHERE part. Any ideas how to fix the query?

Original source

Related problems