2

I'm new to JavaScript/HTML.

I am comparing two dates:

  1. Current Date (d1)

  2. Date FME Workbench was run (d2)

If d1 = 2 the Header Shows the (d2) in green - this works.

If d1 != d2 an alert is created (works) and the (d2) date at the top of the page should be red. Unfortunately nothing happens.

I know this happens because d1 is a string, whilst d2 is a number. However removing toString() for d1 gives me 2033 as a the date, whilst applying it to d2 results in the Alert and Title representing d2 as [Window Object].

var now = new Date();
var y = now.getFullYear().toString();
var m = (now.getMonth() + 1).toString();
var d = now.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var d1 = y + m + d;

var d2 =  toString(20190508) //this number is pulled from FME



if (d1 != d2) {      
  alert("ACHTUNG: Die FME Server Log Workbench wurde heute (" + d1 + ") NICHT ausgeführt! \n\nLetzte Ausführung: " + d2);

  var Titel = "Letzte Ausführung: " + d2.fontcolor("red");
  document.getElementById("demo").innerHTML = Titel;


} else {
  var Titel = "Letzte Ausführung: " + d1.fontcolor("green");
  document.getElementById("demo").innerHTML = Titel;
}
<h1 id="demo"></h1>

I'm therefore unsure how to go about correcting this. Thank you for your time

Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
nkrh
  • 45
  • 5

1 Answers1

3

You have to convert integer to string like this (20190508).toString(). you made a mistake in it thats why you are getting window.object.

try this code.

var now = new Date();
var y = now.getFullYear().toString();
var m = (now.getMonth() + 1).toString();
var d = now.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);

var d1 = y + m + d;

var d2 =  (20190508).toString() //this number is pulled from FME

if (d1 != d2) {
  alert("ACHTUNG: Die FME Server Log Workbench wurde heute (" + d1 + ") NICHT ausgeführt! \n\nLetzte Ausführung: " + d2);

  var Titel = "Letzte Ausführung: " + d2.fontcolor("red");
  document.getElementById("demo").innerHTML = Titel;

} else {
  var Titel = "Letzte Ausführung: " + d1.fontcolor("green");
  document.getElementById("demo").innerHTML = Titel;
}
<h1 id="demo"></h1>
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59