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('cupoms.id', 'valor', 'nome', 'rg', 'funcionario', 'nf','validade', 'username')
.select(Database.raw('DATE_FORMAT(cupoms.created_at, "%d/%m/%Y") as created_at_formated'))
.from('cupoms')
.where('cupoms.id', query)
.join('users', 'users.id', 'id_usuario_fk').first()
1 Like

You should make use of the formatDates method in your model files. See: https://adonisjs.com/docs/4.1/lucid#_formatting_date_fields.