Converting PHP date strings to MySQL timestamps for comparison operations

I’m working with a PHP application that handles dates in YYYY-DD-MM format as strings. My database stores timestamps in MySQL’s standard timestamp format. I need to perform date comparisons between these two different formats but I’m struggling to find a straightforward conversion method.

Here’s what I’m dealing with:

$userDate = '2024-15-03'; // PHP string format
$dbQuery = "SELECT * FROM events WHERE event_date = ?";
// Need to compare with MySQL timestamp column

I’ve tried a few approaches but nothing seems clean or efficient. What’s the best practice for handling this conversion? Should I convert the PHP string to a timestamp before the database query, or is there a MySQL function that can handle this conversion directly in the query? Any guidance would be really helpful.

your date format’s wrong - it should be 2024-03-15, not 2024-15-03. there’s no 15th month lol. if you mean march 15th, fix the format first, then use STR_TO_DATE() in mysql or convert it with php’s DateTime before querying.