Javascript to create Link incl. DYNAMIC DATE

Problem Description:

Some services might use special parts in the URL, that are dynamic.
So is my case, where the link must include today’s date.
I found some resources on the web that gave me an idea and here is my final piece of code.
I added it to a SharePoint site, so users are able to click from there including login and this dynamic date.

Solution:

<div id=’dynLink’> </div>

<script type=”text/javascript”>
window.onload = function(){
var date = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
if(m < 10){m = ‘0’ + m;}
var d = date.getDate();
if(d < 10){d = ‘0’ + d;}
var date = d + “.” + m + “.” + y;

var finalURL = ‘<a target=\”_blank\” href=\”https://first part of the link’ + date + ‘second part of the link\”>Link</a>’;

document.getElementById(‘dynLink’).innerHTML=finalURL;
}
</script>

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...