I am new with JS and have problem with my script. I want to display on my web seniority date for employees. Here is my JS code to calculate it.
var dateObj1 = new Date( '1992/07/07 18:00:00' );
var dateObj2 = new Date();
//get difference in milliseconds
var diffMilliseconds = dateObj1.getTime() - dateObj2.getTime();
//make the difference positive
if( diffMilliseconds < 0 ) diffMilliseconds *= -1;
//convert milliseconds to hours
var diffYears = ( diffMilliseconds / 1000 ) / 60 / 60 / 24 / 365;
//print on console
var num = diffYears;
num = Math.floor(num);
if (num > 1)
{
document.write(num + ' years');
}
else if (num < 1)
{
document.write('less than one year');
}
else
{
document.write(num + ' year');
}
there will be around 45-50 eployees and instead of creating 50 js files want to define employment date var dateObj1 = new Date( '1992/07/07 18:00:00' );
in HTML but not realy know how to do that.
could someone post part of HTML code to be used and part of JS which have to be changed.
thank you.