从Mysql两个表中仅提取不包括时间的日期部分,并在php中进行比较

问题描述:

I have two tables in Database and both fields has the datetime columns I want to extract only the date part form the columns and compare it. MySql give the YYYY-MM-DD HH:MM:SS format and I can't compare because of the time difference even though the date is same.

SELECT * FROM  table1;
SELECT * FROM  table2;

table1.date == table2.date

How can I only compare date excluding time in PHP?

我在数据库中有两个表,两个字段都有日期时间列 我想只提取日期部分表格 列和比较它。 MySql给出YYYY-MM-DD HH:MM:SS格式,由于时间差,我无法比较,即使日期相同。 p>

  SELECT * FROM table1; 
SELECT * FROM table2; 
 
table1.date == table2.date 
  code>  pre> 
 
 

我怎样才能比较排除时间的日期 PHP? p> div>

You can get date+time($table1_date) from Mysql and exclude time in PHP like this:

$full_date = strtotime($table1_date);
$date_only = date("d-m-Y", $full_date);

You can use MySQL's DATE_FORMAT() function to format the date, e.g.:

SELECT DATE_FORMAT(date,'%Y-%m-%d') FROM table;

Once you get the dates from both the tables, you can show/compare them in php.