I'm making a node api using prisma ORM and i'm trying to update a column which i had set with the type DateTime, here is the model, the column is the deleted_at one
model Employee {
id Int @id @default(autoincrement())
name String
created_at DateTime
deleted_at DateTime
}
how can i change it to the current time in my controller? the controller looks like this
export const DeleteCompany = async (req:IEmployee, res:Response) => {
const data:ICompany = req
const deletedCompany = await prisma.employee.update({
where: {
id: Number(data.id)
},
data: {
deleted_at: //what should I put here?
}
})
return res.status(200).json(deletedCompany)
}
I've tried using
now()
but it didnt work.
I'm making a node api using prisma ORM and i'm trying to update a column which i had set with the type DateTime, here is the model, the column is the deleted_at one
model Employee {
id Int @id @default(autoincrement())
name String
created_at DateTime
deleted_at DateTime
}
how can i change it to the current time in my controller? the controller looks like this
export const DeleteCompany = async (req:IEmployee, res:Response) => {
const data:ICompany = req
const deletedCompany = await prisma.employee.update({
where: {
id: Number(data.id)
},
data: {
deleted_at: //what should I put here?
}
})
return res.status(200).json(deletedCompany)
}
I've tried using
now()
but it didnt work.
Share Improve this question asked Feb 2, 2023 at 21:08 Hermes SantosHermes Santos 411 silver badge4 bronze badges2 Answers
Reset to default 6Prisma supports plain javascript dates for setting date fields.
So new Date()
should work fine:
deleted_at: new Date()
To create a current datetime field using prisma model enter this in the field
model Employee {
id Int @id @default(autoincrement())
name String
created_at DateTime @default(now())
deleted_at DateTime @default(now())
}
Using the type DateTime
and adding @default(now())
will generate the current DAte and time to the field