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

132
Visualizações
Days between dates in DayJS UK Format

Im using dayjs, and I'm trying to calculate the days between 2 days so that I can output Today, Tomorrow and X days time

The problem I'm having though seems to be with the date formats

const date1 = dayjs('31/10/2021');
const date2 = dayjs().format("DD/MM/YYYY")

let hours = date2.diff(date1, 'days')

No matter how I try, I'm getting date2.diff is not a function when I add .format to date2. Does anyone know how to format this correctly and get the correct outcome?

If i try const date1 = dayjs('31/10/2021').format("DD/MM/YYYY"); then it errors with invalid date

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

0

You can try the following:

const date1 = dayjs('2021-01-25');
const date2 = '01/11/2020'; // or '2020-11-01'

let hours = date1.diff(date2, 'day')

console.log(hours) // 380

The format function just returns a string. This is why date2.diff is not a function. The diff function is only available for dayjs objects (not for strings).

Docs for difference function: https://day.js.org/docs/en/display/difference

Docs for format function: https://day.js.org/docs/en/display/format

about 4 years ago · Juan Pablo Isaza Relatório

0

const date1 = dayjs('2019-01-25')
date1.diff('2018-06-05', 'day', true)

You don't need to call format function, just use dayjs constructor to convert both dates to dayjs object and return the difference between the 2 dates in number of days.

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