How to compare date when its save as data type text in database

0 Comments

Last updated on

MySQL offers a “STR_TO_DATE” function to convert a date string to a date

$date = date('d-m-Y');
$wpdb->get_results( "SELECT * FROM db_table WHERE STR_TO_DATE(`date`) > '$date'
 " );

*It is not recommended to insert dates into MySQL as text.

Leave a Comment