Action
Date Template Example
Posted by sylumer,
Last update
over 4 years ago
- Unlisted
Steps
-
script
//Set your date of birth here as text between double quotes //e.g. 1980-11-22 const DOB = "1980-11-22";
-
script
function elapsedDaysToNow(p_strDateFrom) { //Get the current date/time let dtTo = new Date(); //Return the elapsed days from the passed in date to now return elapsedDays(p_strDateFrom, dtTo.toISOString().split("T")[0]); } function elapsedDays(p_strDateFrom, p_strDateTo) { //Create date objects form the strings passed in. let dtFrom = new Date(p_strDateFrom); let dtTo = new Date(p_strDateTo); //Calculate the difference in milliseconds. let intDiffMS = dtTo.getTime() - dtFrom.getTime(); //Return that difference in days. //ms * secs * mins * hours => 1,000 * 60 * 60 * 24 = 86,400,000 return intDiffMS / 86400000; } //Set the template tag used in the template draft.setTemplateTag("x", elapsedDaysToNow(DOB));
-
defineTemplateTag
name newcontent
template Day [[x]] Title: Day [[x]] Date: [[date]] Permalink: [[x]] # Day [[x]] {>|}
-
script
let draftNew = new Draft(); draftNew.content = draft.processTemplate("[[newcontent]]"); draftNew.update(); editor.load(draftNew);
Options
-
After Success Default Notification Error Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.