pgrevents Posted June 15, 2009 Share Posted June 15, 2009 I have a field which I am trying to sort to show the last seven days and I have hit a stubmling block can anyone help please <?php $date =date('Y-m-d'); $time = date('h:i:s'); $query = mysql_query("select * FROM programme WHERE expiry <='$dateT$timeZ' "); ?> The field expiry all content is like this 2009-06-15T16:24:00Z Now the code executes but its not showing what I am wanting its showing the fields that are empty is there anyway to make this to work Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2009 Share Posted June 15, 2009 To compare values, the format must be exactly the same. 2009-06-15T16:24:00Z is not the same as the result of date('Y-m-d') and date('h:i:s') Why is expiry not a DATETIME data type? Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855979 Share on other sites More sharing options...
pgrevents Posted June 15, 2009 Author Share Posted June 15, 2009 can i change it to that? i parsed all the information froma text file into the db Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855985 Share on other sites More sharing options...
pgrevents Posted June 15, 2009 Author Share Posted June 15, 2009 but 2009 is Y- 06 is month m- and day is -d same for the hours Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855987 Share on other sites More sharing options...
Ken2k7 Posted June 15, 2009 Share Posted June 15, 2009 What the heck is $dateT and $timeZ? Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855991 Share on other sites More sharing options...
pgrevents Posted June 15, 2009 Author Share Posted June 15, 2009 this field has 2009-06-15T16:24:00Z in it Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855993 Share on other sites More sharing options...
Ken2k7 Posted June 15, 2009 Share Posted June 15, 2009 WTF? What type of data is that? Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855995 Share on other sites More sharing options...
pgrevents Posted June 15, 2009 Author Share Posted June 15, 2009 im pulling it from an autogenerated file from a 3rd party so no control over it Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855997 Share on other sites More sharing options...
Ken2k7 Posted June 15, 2009 Share Posted June 15, 2009 If expiry is *not* of a date type, that SQL is fail. Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-855999 Share on other sites More sharing options...
pgrevents Posted June 15, 2009 Author Share Posted June 15, 2009 but the field is there i have pulled from it before. What I am needing is to sort in lets say the last 7 days Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-856004 Share on other sites More sharing options...
kickstart Posted June 15, 2009 Share Posted June 15, 2009 Hi Echo out the SQL statement and check it really has what you want in it. Wouldn't surprise me if php is trying to use fields called $dateT and $timeZ, and getting rather confused. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-856093 Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2009 Share Posted June 15, 2009 Assuming that php correctly figures out '$dateT$timeZ' (you might need to do '{$date}T{$time}Z'), the h in date('h:i:s'); should be H to match the format of the data. Quote Link to comment https://forums.phpfreaks.com/topic/162202-mysql-where-statement/#findComment-856241 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.