December 5th, 2012, 09:44 AM
i just inhered a db where the dates are stored as a string so i dont think i can use the between so do my search
so i was going to write it like
$query="select * from table where date_column between "2001-01-01" and "2013-01-12";
i dont really like this but i was wondering how can build the a string of dates between 2 dates
SELECT * FROM table WHERE
`fieldname` = 'createdtime'
`postvalue` LIKE '%2012-12-04%'
OR `postvalue` LIKE '%2012-12-05%'
December 5th, 2012, 09:49 AM
This sounds more like a MySQL question rather than PHP. You might get better results having this thread moved to that forum (click on the red triangle in the upper right).
There are 10 kinds of people in the world. Those that understand binary and those that don't.
December 5th, 2012, 10:06 AM
if you have any chance to fix the database, then do it. That's the only real solution. Working with broken data is horrible, especially when it's complicated data like dates.
If you can't get to the database, you'll have to parse the date strings each time you use them. Use STR_TO_DATE() or something.
But don't fumble with string comparisions, that'll get you nowhere.