{"id":177,"date":"2018-06-11T12:39:02","date_gmt":"2018-06-11T12:39:02","guid":{"rendered":"http:\/\/4us2use.at\/?p=177"},"modified":"2018-07-18T12:47:09","modified_gmt":"2018-07-18T12:47:09","slug":"javascript-to-create-link-incl-dynamic-date","status":"publish","type":"post","link":"http:\/\/4us2use.at\/?p=177","title":{"rendered":"Javascript to create Link incl. DYNAMIC DATE"},"content":{"rendered":"<p>Problem Description:<\/p>\n<p>Some services might use special parts in the URL, that are dynamic.<br \/>\nSo is my case, where the link must include today&#8217;s date.<br \/>\nI found some resources on the web that gave me an idea and here is my final piece of code.<br \/>\nI added it to a SharePoint site, so users are able to click from there including login and this dynamic date.<\/p>\n<p>Solution:<\/p>\n<p>&lt;div id=&#8217;dynLink&#8217;&gt; &lt;\/div&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nwindow.onload = function(){<br \/>\nvar date = new Date();<br \/>\nvar y = date.getFullYear();<br \/>\nvar m = date.getMonth() + 1;<br \/>\nif(m &lt; 10){m = &#8216;0&#8217; + m;}<br \/>\nvar d = date.getDate();<br \/>\nif(d &lt; 10){d = &#8216;0&#8217; + d;}<br \/>\nvar date = d + &#8220;.&#8221; + m + &#8220;.&#8221; + y;<\/p>\n<p>var finalURL = &#8216;&lt;a target=\\&#8221;_blank\\&#8221; href=\\&#8221;https:\/\/first part of the link&#8217; + date + &#8216;second part of the link\\&#8221;&gt;Link&lt;\/a&gt;&#8217;;<\/p>\n<p>document.getElementById(&#8216;dynLink&#8217;).innerHTML=finalURL;<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<span id=\"post-ratings-177\" class=\"post-ratings\" data-nonce=\"f25e406aa2\"><img id=\"rating_177_1\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"1 Star\" title=\"1 Star\" onmouseover=\"current_rating(177, 1, '1 Star');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_177_2\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"2 Stars\" title=\"2 Stars\" onmouseover=\"current_rating(177, 2, '2 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_177_3\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"3 Stars\" title=\"3 Stars\" onmouseover=\"current_rating(177, 3, '3 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_177_4\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"4 Stars\" title=\"4 Stars\" onmouseover=\"current_rating(177, 4, '4 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_177_5\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"5 Stars\" title=\"5 Stars\" onmouseover=\"current_rating(177, 5, '5 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/> (No Ratings Yet)<br \/><span class=\"post-ratings-text\" id=\"ratings_177_text\"><\/span><\/span><span id=\"post-ratings-177-loading\" class=\"post-ratings-loading\"><img src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/loading.gif\" width=\"16\" height=\"16\" class=\"post-ratings-image\" \/>Loading...<\/span>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description: Some services might use special parts in the URL, that are dynamic. So is my case, where the link must include today&#8217;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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/4us2use.at\/?p=177\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Javascript to create Link incl. DYNAMIC DATE&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/177"}],"collection":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=177"}],"version-history":[{"count":4,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions"}],"predecessor-version":[{"id":184,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions\/184"}],"wp:attachment":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}