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

127
Views
Get all specific day in specific end date in JavaScript

I am trying to get all day (input by me) in a specific end date (input by me).

example :

I have day 1 and I have end date 10/12/2021

beginning from new Date():

output must be: 1/10/2021 1/11/2021 1/12/2021

day 1 for this month is not included because we are in day 20 and day 20 > day 1

Same, I chose day 20 (example) and end date = 19/12/2021 day 20 in end date not included because day 20 > end date day

I have already tried that as simple using if condition, but not great work because in this case, I have 8 conditions!

I want a simple code that works for this situation.

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

0

Hope that is what you wanted. You can simplify it more if you want.

const getRemainingDates = function(beginningDay, endDate){
  const today = new Date()
  const [endDateDay,endDateMonth,endDateYear] = endDate.split("/");
  const remainingMonth = endDateMonth - (today.getMonth()+1);
  for(let i = 0; i <= remainingMonth; i++){
    if(i === 0){
        if(beginningDay>today.getDate() && beginningDay>endDateDay){
          console.log(`${beginningDay}/${today.getMonth()+1+i}/${today.getFullYear()}`)
        }
        else {}
    }
    if(i !== 0)console.log(`${beginningDay}/${today.getMonth()+1+i}/${today.getFullYear()}`)
  }
}

getRemainingDates(21,"12/12/2021");
console.log()
getRemainingDates(1,"12/12/2021");

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!