date
Insert the date, day of the week can be calculated a few days after.

Script key: Insert the date, day of the week can be calculated a few days after.

Posted by @harshalshinde (based on @feelingplace)

Install

Details

Label date
Voice Over Insert the date, day of the week can be calculated a few days after.
Script
//Please start by selecting the number of days before or numbers.

var daysBefore = getSelectedText();
var addDays = -daysBefore;
var nowdate = new Date();
var year = nowdate.getFullYear();
var month = nowdate.getMonth() + 1;
var date = nowdate.getDate();
function computeDate(year, month, day, addDays) {
  dt = new Date(year, month - 1, day);
  baseSec = dt.getTime();
  addSec = addDays * 86400000;
  targetSec = baseSec - addSec;
  dt.setTime(targetSec);
  return dt;
    }
beforeDate = computeDate(year, month, date, addDays);
var week = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var dayOfWeek = week[beforeDate.getDay()];
var buf = beforeDate.getDate() + "-" + (beforeDate.getMonth() + 1) + "-" + beforeDate.getFullYear() + ", "+ dayOfWeek;
var selRange = getSelectedRange();
setSelectedText(buf);
setSelectedRange(selRange[0]+buf.length, 0);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus