It clearly states that the function is not available for sqlite. Look for alternatives http://www.sqlite.org/lang_datefunc.html
May 3, 2016
9
Level 7
DATE_FORMAT() FAILING IN SQLITE
I have a method calculating the number of user signups;
public function getSignupsCount()
{
$users = DB::select('select count(id) as count, DATE_FORMAT(created_at, "%M %y") as months
from users group by months order by created_at');
return $users;
}
My functional tests use Sqlite based database. When testing this method, I get the error; `
SQLSTATE[HY000]: General error: 1 no such function: DATE_FORMAT (SQL: select count(id) as count, DATE_FORMAT(created_at, "%M %y") as months from users group by months order by created_at)
I am wondering whether to change my test DB to Mysql or is there a way to re-write this and retain my existing test database?
Level 50
If your production DB is mysql and you're doing mysql-specific (or at least not DB-agnostic SQL) then you're probably better off using mysql in your tests, imho. Sqlite is great for a lot of things, but not everything. For instance this can bite you in tests vs. production :
sqlite> create table hello (number int);
sqlite> .schema hello
CREATE TABLE hello (number int);
sqlite> insert into hello values(1);
sqlite> select * from hello;
1
sqlite> insert into hello values('yay');
sqlite> select * from hello;
1
yay
1 like
Please or to participate in this conversation.