A. Dziedziczak A. Dziedziczak - 6 months ago 64
MySQL Question

How to use CURRENT_DATE() function with doctrine 2 with specified format string?

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


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");


$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 dispence with all those escape characters which just server to confuse the eye. Also $variables are automatically expanded inside a double quoted string.