0

Why this script won't work? It should redirect after 28/09/2016 00:01PM

<script language="javascript">
// Redirect naar index-afgesloten.html

var currentdate = new Date();

var datetime = "Last Sync: " + currentdate.getDate() + "/"+(currentdate.getMonth()+1) 
+ "/" + currentdate.getFullYear() + " @ " 
+ currentdate.getHours() + ":" 
+ currentdate.getMinutes();

if(new Date() > "28/09/2016 00:01PM") // Datum omschakeling
{
 location.href ="index-afgesloten.html"; // redirect url
}

</script>

Thanks

Aaron Davis
  • 1,731
  • 10
  • 13
Benny
  • 67
  • 4

2 Answers2

0

As the comment points out, this is javascript and not java :)

Right now you're creating a Date object inside the if-statement, which creates a date at the current time. You then try to compare to a string, which is not possible. If you want to compare dates, you should create 2 date objects and use the dataObject.getTime() method, in order to compare them. I found a link that should help you out:

Compare two dates with JavaScript

Good luck!

Community
  • 1
  • 1
Jakob
  • 21
  • 2
0

Try this and change tags :)

var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDate() + "/" + (currentdate.getMonth() + 1) +
    "/" + currentdate.getFullYear() + " @ " +
    currentdate.getHours() + ":" +
    currentdate.getMinutes();

var dateAfter = new Date('2016-09-28T00:00:00');

if (currentdate > dateAfter) // Datum omschakeling
{
    location.href = "index-afgesloten.html";
}
Shaq
  • 377
  • 5
  • 16