Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
Javascript: Add 30 days to date?

I have a dateObject pulled from my database: 2021-01-02T15:12:05.000Z. I'd like to add 30 days to that date so that the end date is: 2021-02-01T15:12:05.000Z. How would I get this to work?

Reading various posts, I've tried:

let storePlanStartDate = dateObject;

storePlanStartDate.setDate(storePlanStartDate.getDate() + 30)

//returns: 1614784325000

I think the return value: 1614784325000 may be what I'm looking for. However, I'm struggling to convert it back to the same format as the original database return so that I can save the updated date.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What you're seeing is just the default representation of a date - dates are stored as number of milliseconds since datum.

If you format the value as an ISO string (for example) you'll see it actually has the value you expected

let storePlanStartDate = new Date("2021-01-02T15:12:05.000Z");

storePlanStartDate.setDate(storePlanStartDate.getDate() + 30)

console.log(storePlanStartDate.toISOString());

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda