-1
Good morning, you guys, I come from the Java world and am starting in Nodejs.
I’m having a hard time understanding how to work with dates and times at Nodejs.
This is an example of the model I want to use:
export interface teste extends mongoose.Document {
descricao: string,
dataTeste: ????,
horarioInicial: ????,
horarioFinal: ????,
dataHoraRegistro: ????
}
const testeSchema = new mongoose.Schema({
descricao:{
type: String,
required: true,
maxlength: 200,
minlength: 3
},
dataTeste:{
type: ?????,
required: true
},
horarioInicial:{
type: ?????,
required: true
},
horarioFinal:{
type: ?????,
required: true
},
dataHoraRegistro:{
type: ?????,
required: true
}
}
export const Teste = mongoose.model<Teste>('Teste', testeSchema)
In all the places I left ??? I don’t know what to put.
- In the dataThis field I need to record only dates, without the time.
- In the time fieldsInitial and scheduleFinal I need to store only hours, no dates.
- In the Datemark field I need to store the moment something happened (date and time).
How do you do it?
Man, what a fantastic response! The tip was excellent. I had put the time as a string, but then I wasn’t sure how to make calculations with the hours. I will also try to reduce the amount of code. Thank you very much for the attention on the answer.
– Rafael Bomfim
I’m glad I helped! : D
– Tiago pedro