str_to_date() syntax queries
Posted: Mon Dec 03, 2007 4:04 am
G'day peeps,
Hopefully this is a simple query, but I 'm not sure exactly how the str_to_date() query works...
I have a database which has a VARCHAR field (called RemoveBy) containing dates in the format DD/MM/YY and DD/MM/YYYY, and I need to run a query to find records where the RemoveBy date is greater than the current date ie the date hasn't yet been reached.
So, having been browsing t'internet I found something to check an exact known date -
SELECT * from tablename WHERE str_to_date(RemoveBy, '%d/%m/%Y') = str_to_date('06/12/2007', '%d/%m/%Y')";
- which I thought should find any records with a RemoveBy date of 06/12/2007 - however it doesn't work, so is my syntax correct? And I suppose I'd have to add an extra query to find dates like 06/12/07 as well?
And then, how do I check that against the current date? curdate() returns a value as YYYY-MM-DD, so can I convert it to check a different date format?
Cheers.
Hopefully this is a simple query, but I 'm not sure exactly how the str_to_date() query works...
I have a database which has a VARCHAR field (called RemoveBy) containing dates in the format DD/MM/YY and DD/MM/YYYY, and I need to run a query to find records where the RemoveBy date is greater than the current date ie the date hasn't yet been reached.
So, having been browsing t'internet I found something to check an exact known date -
SELECT * from tablename WHERE str_to_date(RemoveBy, '%d/%m/%Y') = str_to_date('06/12/2007', '%d/%m/%Y')";
- which I thought should find any records with a RemoveBy date of 06/12/2007 - however it doesn't work, so is my syntax correct? And I suppose I'd have to add an extra query to find dates like 06/12/07 as well?
And then, how do I check that against the current date? curdate() returns a value as YYYY-MM-DD, so can I convert it to check a different date format?
Cheers.