Reputation: 25
I stored expiry date field as var char datatype in MySQL table. Now i need to compare expiry date with current date. How to convert var char datatype as date in php coding and compare date in select query where condition.
Upvotes: 0
Views: 4694
Reputation: 79
This works for me:
SELECT * FROM table_name WHERE start_date <= CURDATE() AND end_date >= CURDATE()
Upvotes: 0
Reputation: 917
why don't you do it in the query itself.
$current_date=date("Y-m-d");
mysql_query("select * from your_table where STR_TO_DATE(expiry_date,'%Y-%M-%D')>'".$date."');
or
You can do it in php itself
if(strtotime($current_date) > strtotime($row['date'])) {
//your code
}
Upvotes: 1