Date
Output format: Weekday, DD-MM-YYYY. If a number is selected, calculates date offset by those many number of days (+ or —). If nothing selected, it outputs the current date

Script key: Output format: Weekday, DD-MM-YYYY. If a number is selected, calculates date offset by those many number of days (+ or —). If nothing selected, it outputs the current date

Posted by @harshalshinde

Install

Details

Label Date
Voice Over Output format: Weekday, DD-MM-YYYY. If a number is selected, calculates date offset by those many number of days (+ or —). If nothing selected, it outputs the current date
Script
//UPDATED. Output format: Weekday, DD-MM-YYYY. If a number is selected, calculates date offset by those many number of days (+ or —). If nothing selected, it outputs the current date

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;
    }
afterDate = computeDate(year, month, date, addDays);
var week = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var dayOfWeek = week[afterDate.getDay()];

dd = afterDate.getDate()
if(dd<10) {
    dd='0'+dd
} 
mm = afterDate.getMonth() + 1
if(mm<10) {
    mm='0'+mm
} 
yyyy = afterDate.getFullYear()
var buf = dayOfWeek+', '+dd+'-'+mm+'-'+yyyy+' ';

var selRange = getSelectedRange();
setSelectedText(buf);
setSelectedRange(selRange[0]+buf.length, 0);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus