MySQL中将这种格式的日期和时间与当前日期和时间进行比较的最佳方法是什么?
数据以日期时间类型存储在数据库中
我需要重新格式化我的数据吗?
答案 0 :(得分:0)
仅在日期未过去时返回true
这将直接在我的数据库中作为查询来解决问题:
SELECT c.entity_id AS entity_id,
c.field_course_category_terms_tid AS field_terms_tid,
e.entity_type AS entity_type,
e.field_end_date_value AS field_end_date_value
FROM
field_data_field_terms c
INNER JOIN field_data_field_end_date e ON c.entity_id = e.entity_id
WHERE
e.field_end_date_value > curdate()
在我的drupal查询中,它起到了作用:
$query = db_select('table1', 'c');
$query->innerJoin('table2', 'e', 'c.entity_id = e.entity_id');
$query->fields('c',array('entity_id','field_terms_tid'))
->fields('e',array('entity_type', 'field_end_date_value'))
->where('e.field_end_date_value now()');
->execute();
$result = $result->fetchAll();