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

117
Views
Redirect website between two specific dates using JavaScript

I'm in need of some help regarding redirecting my website during certain days each year. I want to be able to redirect my website from the current one (A) to the other one (B) between 1st of March to 15th of April.

I can't find any way to do this without making a weird cluster of websites that loads and redirect the user back and forth to multiple pages. I tried to add certain code in the script and such but no success. I'm trying also to not include a specific year only the dates so it runs same dates each year without modification. The code I use today for the season is:

<script>var date=new Date();
if(date.getMonth()==3){
  window.location="https://www.MYWEBSITE.com/site_B.html"}</script>

which only redirects the full months of April which isn't optimal at all. All ideas are welcome and I appreciate all help.

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

0

If you're not concerned about locales and different timezones, you can use this.

let today = new Date().getTime();
// use current year only
let year = new Date().getFullYear();
let s = `${year}-11-15`,  e = `${year}-12-15`
let startDate = new Date(s).getTime();
let endDate = new Date(e).getTime();
if (today >= startDate && today <= endDate) {
  console.log('redirect');
  //window.location="https://www.MYWEBSITE.com/site_B.html";
}

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!