dongyue8640 2016-10-03 15:12
浏览 32
已采纳

如何使用带有指定格式字符串的doctrine 2的CURRENT_DATE()函数?

I have no idea how to set specified date format to query with CASE WHEN. What i try to do is to create a select that will look like one bellow.

$qb -> select('
              CASE WHEN ps.paymentDate >= (new \DateTime(\'%Y-%m-01\')) THEN \'true\' ELSE \'false\' END as myVar
');

I looked for the solution in the internet but i haven't found it. Am i thinking about the whole problem right?

Previous code in mysql looked like this:

IF(ps.payment_date >= DATE_FORMAT(CURDATE(),\'%Y-%m-1\'),\'true\',\'false\') as myVar   
  • 写回答

1条回答 默认 最新

  • dongzhanyan3667 2016-10-03 15:28
    关注

    Like this,

    $d = new \DateTime();
    $sd = $d->format('Y-m-01');
    $qb -> select("CASE WHEN ps.paymentDate >= '$sd' THEN 'true' ELSE 'false' END as myVar");
    

    Or

    $q = "IF(ps.payment_date >= DATE_FORMAT(CURDATE(),'%Y-%m-01'),'true','false') as myVar";
    

    NOTE: If you use single quotes inside a Double quoted string literal, you can dispense with all those escape characters which just server to confuse the eye. Also $variables are automatically expanded inside a double quoted string.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?