woodsmic Posted April 9, 2009 Share Posted April 9, 2009 I wrote a script sometime ago, which pulls records from a mysql database. I use a html form which passes the variables to the script, which can find records by order number, email address or between certain dates. Since my host has upgraded PHP on his server, the query I used to pull the records between certain dates has stopped working. Below is the query used in my script: $datefrom is passed from a form. $dateto is passed froma form. datetime is the field in my database. $sql = "SELECT * FROM orders WHERE DATE_FORMAT(datetime,'%Y%m%d') >= DATE_FORMAT('$datefrom','%Y%m%d') and DATE_FORMAT(datetime,'%Y%m%d') <= DATE_FORMAT('$dateto','%Y%m%d') ORDER BY datetime"; I think it is something to do with DATE_FORMAT.. As I say it used to work, nothing has changed apart from the php version on the server. Any ideas? I have tried for hours, which has acheived nothing except giving me a headache! Thanks in advance guys. Mike. Link to comment https://forums.phpfreaks.com/topic/153293-query-in-php-script-not-working-but-is-used-to/ Share on other sites More sharing options...
woodsmic Posted April 9, 2009 Author Share Posted April 9, 2009 Just to add: $datefrom and $dateto are in the format : $datefrom = date("Ymd", $datefromform); datetime comes from the database in the format "2007-01-30 20:20:20" I need both to be in the same format so the query can work, but i dont know how. Cheers! Link to comment https://forums.phpfreaks.com/topic/153293-query-in-php-script-not-working-but-is-used-to/#findComment-805371 Share on other sites More sharing options...
Ashoar Posted April 9, 2009 Share Posted April 9, 2009 Try changing the formats and then see how it goes: $datefrom=date("U"); //get unix timestamp EDIT: Forgot to add: $time=date("F j, Y, g:i a"); Link to comment https://forums.phpfreaks.com/topic/153293-query-in-php-script-not-working-but-is-used-to/#findComment-805377 Share on other sites More sharing options...
revraz Posted April 9, 2009 Share Posted April 9, 2009 Echo $sql and post the result. Link to comment https://forums.phpfreaks.com/topic/153293-query-in-php-script-not-working-but-is-used-to/#findComment-805483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.