Jump to content

STR_TO_DATE returns nothing


magnetica

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/182712-str_to_date-returns-nothing/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.