Sri Dhar
Sri Dhar

Reputation: 25

How to compare date with current date in php

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

Answers (2)

John Fischer
John Fischer

Reputation: 79

This works for me:

SELECT * FROM table_name WHERE start_date <= CURDATE() AND end_date >= CURDATE()

Upvotes: 0

Rahul Singh
Rahul Singh

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

Related Questions