Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
dayjs - not a function

I'm passing two dayjs date to Vars.date global variables.

var dayjs = require("dayjs") for import
   
Vars.date1 = dayjs(whateverdate1("add", 2)).format('MMM D, YYYY')
Vars.date2 = dayjs(whateverdate2("add", 2)).format('MMM D, YYYY')

const date1 = Vars.date1
const date2 = Vars.date2
let diff = date1.diff(date2, 'month')
console.log('diff' + diff)

error: TypeError: date1.diff is not a function

I am unable to use diff and get methods, always 'not a function'

What did I miss?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Make sure that Day.js supports the require() function. If it is import-based, you need to maybe change the import to that.

So, just try doing the following.

import dayjs from "dayjs";

Links

  • npm Package
  • Official Day.js website
about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you had two problems:

  1. add() should be called like dayjs().add(2, 'month')
  2. Your were trying to call diff() on a string (the output of dayjs().format()) rather than a Dayjs object

Here's how you can create two dayjs objects and find their difference in months:

const dayjs = require("dayjs")
// or:
// import dayjs from "dayjs";

const date1 = dayjs()   // Dayjs object of current month
const date2 = dayjs().add(2, "month") // Dayjs object of 2 months from now

date2.diff(date1, "month") // 2
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda