Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

648
Views
Luxon: cómo obtener el número de días n entre dos fechas

Supongamos que hay dos fechas: 2022-01-10 y 2022-08-20.
El usuario puede escribir un día de un mes cuando una acción debe ejecutarse repetidamente una vez al mes entre estas fechas.
Entonces, si el usuario escribe "25", la acción debe ejecutarse 7 veces, porque la fecha de finalización está fuera de rango.

¿Cómo obtener tal resultado usando luxon en JavaScript? Necesito tener una cantidad de fechas coincidentes O (eso sería aún mejor) una lista de estas fechas.

Otro ejemplo:

Aporte:
Día de un mes: 5
Fecha de inicio: 2022-07-08
Fecha de finalización: 2022-09-05

Rendimiento esperado:
2022-08-05
2022-09-05

Gracias por adelantado.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Un poco raro, pero esto debería llevarte por un camino decente...

 const startDate = luxon.DateTime.utc(2022, 1, 5, 0, 0, 0, 0) const endDate = luxon.DateTime.utc(2022, 6, 5, 0, 0, 0, 0) const diff = endDate.diff(startDate, ["months"]) // we get a diff of `5` here, let's generate the date map next console.log(diff.toObject()) const possibleDates = [] const dayOfMonthInput = 2 const targetDateByInput = luxon.DateTime.utc(2022, 1, dayOfMonthInput, 0, 0, 0, 0) for ( let i = 0,maybeDate=targetDateByInput; i <= diff.months; i++, maybeDate = targetDateByInput.plus({ months: i })) { // is maybeDate valid after START date? if (maybeDate.startOf('day') > startDate.startOf('day')) { // is maybeDate valid BEFORE end date? if (maybeDate.startOf('day') < endDate.startOf('day')) { // add to collection possibleDates.push(maybeDate) } } } // output possible dates console.log(possibleDates)
 <script src="https://cdn.jsdelivr.net/npm/luxon@1.25.0/build/global/luxon.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!