maxelct Posted November 19, 2008 Share Posted November 19, 2008 Hi I have a database that stores dates as yyyy-mm-dd and I need to query it using yyyy I noticed that the field where this date is stored is of type char(10) - which looks odd to me.... The uers puts in $dateInput and I added 01.01 and 12.31 to the yyyy like this: $lowDate = $dateInput.'-01-01'; $highDate = $dateInput.'-12-31'; and so get this query: .... WHERE table.field BETWEEN 2000-01-01 AND 2000-12-13 if ($result) shows ture but the query provides no returns which I know it should because i have looked at the data. Could anybody please help me. Is it something to do with the field type or am I doing something wrong with the query? thanks E Quote Link to comment https://forums.phpfreaks.com/topic/133338-date-range-query-not-working/ Share on other sites More sharing options...
c0rnf3d Posted November 19, 2008 Share Posted November 19, 2008 id change the col to date Quote Link to comment https://forums.phpfreaks.com/topic/133338-date-range-query-not-working/#findComment-693564 Share on other sites More sharing options...
maxelct Posted November 19, 2008 Author Share Posted November 19, 2008 thanks for that I am afraid it didnt really mean a lot to me. Any chance someone could expand a little bit? thanks E Quote Link to comment https://forums.phpfreaks.com/topic/133338-date-range-query-not-working/#findComment-693614 Share on other sites More sharing options...
fenway Posted November 19, 2008 Share Posted November 19, 2008 Don't store dates in CHAR fields... that was it. Quote Link to comment https://forums.phpfreaks.com/topic/133338-date-range-query-not-working/#findComment-693636 Share on other sites More sharing options...
maxelct Posted November 19, 2008 Author Share Posted November 19, 2008 Well yes I kind of figured that was the problem. Trouble is I have been given this database to work with. What can I do to solve the problem? Quote Link to comment https://forums.phpfreaks.com/topic/133338-date-range-query-not-working/#findComment-693764 Share on other sites More sharing options...
c0rnf3d Posted November 19, 2008 Share Posted November 19, 2008 not sure if you can just change the column type... if not, add a column for date and write some php to grab then update the date column with the date from the char column. verify it. delete char col. rename date col. Quote Link to comment https://forums.phpfreaks.com/topic/133338-date-range-query-not-working/#findComment-693824 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.