Error when trying to format date in query

Hey devs

Im trying to format created_at in my query.
There is a answered question in forum about this but when i try to do the same i get this error

select "cupoms"."id", "valor", "nome", "rg", "funcionario", "nf", "validade", "username", DATE_FORMAT(cupoms.created_at, "%d/%m/&Y") as created_at_formated from "cupoms" inner join "users" on "users"."id" = "id_usuario_fk" where "cupoms"."id" = $1 limit $2 - column "%d/%m/&Y" does not exist

My Query

const cupoms = await Database
.select('', 'valor', 'nome', 'rg', 'funcionario', 'nf','validade', 'username')
.select(Database.raw('DATE_FORMAT(cupoms.created_at, "%d/%m/%Y") as created_at_formated'))
.where('', query)
.join('users', '', 'id_usuario_fk').first()
1 Like

You should make use of the formatDates method in your model files. See: