Convert strftime in SQLite request to MySQL

Paul picture Paul · Jun 23, 2014 · Viewed 10.7k times · Source

I converted the SQLite line

WHERE strftime('%d%m', orders.created_at) = .......

directly to a MySQL monster:

WHERE CONCAT(CAST(DAY(orders.created_at) AS CHAR), LPAD(CAST(MONTH(orders.created_at) AS CHAR), 2, '0')) = .........

Please, help me to rewrite it to a shorter one.

Answer

Joachim Isaksson picture Joachim Isaksson · Jun 23, 2014

STRFTIME() in SQLite is similar to DATE_FORMAT() in MySQL with reversed parameters.

Since %d and %m map to the same thing in both, your expression can simply be written as;

WHERE DATE_FORMAT(orders.created_at, '%d%m') = .......