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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.