magnetica Posted November 23, 2009 Share Posted November 23, 2009 Heres my whole sql query $sql = "SELECT * FROM videos WHERE tags LIKE '%$query%' OR name LIKE '%$query%' AND post_date BETWEEN STR_TO_DATE($sdate, '%d,%m,%Y') AND STR_TO_DATE($edate, '%d,%m,%Y') ORDER BY thumbs_up ASC LIMIT $offset, $rowsperpage"; Forget everything else and concentrate on: post_date BETWEEN STR_TO_DATE($sdate, '%d,%m,%Y') AND STR_TO_DATE($edate, '%d,%m,%Y') Now I don't get any errors when I put this in my sql but nothing shows up. post_date is a 'postdate' in mySQL. $sdate and $edate are 'yyyy-mm-dd' Page can be viewed at http://youtubecentral.net16.net/index.php Have I done something wrong? Please ask if you need me to elaborate further Thanks you Quote Link to comment https://forums.phpfreaks.com/topic/182712-str_to_date-returns-nothing/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 23, 2009 Share Posted November 23, 2009 What data type is post_date? You can only do greater-than/less-than (i.e. BETWEEN) date comparisons when the format can be comparied by magnitude (i.e. yyyy-mm-dd or a Unix Timestamp) which is why the DATE and DATETIME data types store dates as yyyy-mm-dd. If $sdate and $edate are 'yyyy-mm-dd', they are already in the correct format for the comparison and you don't need to use STR_TO_DATE on them. You should store post_date as a DATE or DATETIME data type if you expect your database queries to function efficiently. Quote Link to comment https://forums.phpfreaks.com/topic/182712-str_to_date-returns-nothing/#findComment-964381 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.