我有一个sql查询,它返回3个最新的格式,但在我将fin\u date列类型从string更改为date并使用特定格式后,它就不起作用了:
$today = JFactory::getDate()->toFormat('%d/%m/%Y');
// echo $today==> 18/12/2018
$query = "SELECT p.fin_date, pfr.product_name, p.ville"
." FROM #__virtuemart_products as p"
." LEFT JOIN #__virtuemart_products_fr_fr as pfr on pfr.virtuemart_product_id = p.virtuemart_product_id"
." WHERE p.published = 1 AND p.product_parent_id != 0 AND str_to_date(p.fin_date,'%d/%m/%Y') >= $today "
." LIMIT 4 "
;
甚至我把它改成:
$query = "SELECT str_to_date(p.fin_date,'%d/%m/%Y'), pfr.product_name, p.ville"
." FROM #__virtuemart_products as p"
." LEFT JOIN #__virtuemart_products_fr_fr as pfr on pfr.virtuemart_product_id = p.virtuemart_product_id"
." WHERE p.published = 1 AND p.product_parent_id != 0 AND str_to_date(p.fin_date,'%d/%m/%Y') >= $today "
." LIMIT 4 "
;
1条答案
按热度按时间4jb9z9bj1#
不能比较日期(的输出)
str_to_date
),将在Y-m-d
内部格式化为d/m/Y
格式。你需要$today
变量输入Y-m-d
格式使用或者在查询中转换它。