I have some code that's supposed to compare the date in a MySQL field against today's date, and it just doesn't work. Help. The field (varchar) has a date like 6/29/2009 in it, and assuming today is 6/23/2009 why doesn't this work properly: UPDATE `tbl_name` SET `active` = '1' WHERE `field` >= 'date("m/d/Y")'
You need to convert the varchar field to a valid date before it can be compared. Try something like this... UPDATE `tbl_name` SET `active` = '1' WHERE STR_TO_DATE(`field`, '%m/%d/%Y') >= NOW() Not sure what date you're trying to compare, so I used now. Also STR_TO_DATE in this case will put the date into a mysql date format (YYYY-MM-DD), not the same as the varchar field. Probably the best way to test is to do selects until you get what you are looking for. Then put it into an update. SELECT * FROM `tbl_name` WHERE STR_TO_DATE(`field`, '%m/%d/%Y') >= NOW()