SmartBlocks icon indicating copy to clipboard operation
SmartBlocks copied to clipboard

get the date ____ days from today

Open dlccyes opened this issue 4 years ago • 0 comments

✂️ Copy of your #42SmartBlock from Roam

  • #42SmartBlock fromtoday
    • <%JAVASCRIPT:
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var today = new Date();
difference = parseInt(prompt('How many days from today?'))*24*3600*1000;
var d = new Date(today.getTime() + difference);
var d_str = `${d.getDate()}`;
if (d_str.length==2 && d_str[0]==1){
  var th = 'th';
}
else {
  if (d.getDate()%10 == 1){
  	var th = 'st';
  }
  else if (d.getDate()%10 == 2){
    var th = 'nd';
  }
  else if (d.getDate()%10 == 3){
    var th = 'rd';
  }
  else {
    var th = 'th';
  }
}
msg = `[[${months[d.getMonth()]} ${d.getDate()}${th}, ${d.getFullYear()}]]`;
return msg

%>

📋 Describe the SmartBlock

  1. type jj fromtoday
  2. enter a number in the pop-up box
  3. will return the date X days from today

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

Roam42

please paste the code part in a javascript codeblock, and place it in the the line after <%JAVASCRIPT:, and the line before %> (in the same block) make sure the layout looks like the screenshots below (codes in the screenshots are outdated) image image

📷 Screenshot of your #42SmartBlock workflow/template from Roam

image image image

dlccyes avatar Feb 13 '21 08:02 dlccyes