Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert strftime in SQLite request to MySQL

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.

like image 417
Paul Avatar asked Jun 23 '14 08:06

Paul


1 Answers

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') = .......
like image 97
Joachim Isaksson Avatar answered Oct 04 '22 09:10

Joachim Isaksson