While someone has already covered this ground I had built a solution using JS before I saw the reply:
Here's mine for reference, it seems to work okay:
Retrospective
Triggered by any of the following:
The exact case string “;;retro” is typed (then deleted)
Will execute the following actions:
Execute JavaScript For Automation
'use strict';
(function run() {
var ordinal_suffix_of = function( i ) {
var j = i % 10,
k = i % 100;
if( j == 1 && k != 11 ) {
return "st";
}
if( j == 2 && k != 12 ) {
return "nd";
}
if( j == 3 && k != 13 ) {
return "rd";
}
return "th";
};
var form_date = function( d ) {
var day = d.getDate();
var month = d.toLocaleString( 'default', { month: 'long' } );
var year = d.getFullYear();
return month + " " + day + ordinal_suffix_of( day ) + ", " + year;
};
var kme = Application("Keyboard Maestro Engine");
var today = new Date();
var last_week = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 7 );
kme.setvariable( "last_week", { to: form_date( last_week ) } );
var last_month = new Date( today.getFullYear(), today.getMonth() - 1, today.getDate() );
kme.setvariable( "last_month", { to: form_date( last_month ) } );
var last_quarter = new Date( today.getFullYear(), today.getMonth() - 3, today.getDate() );
kme.setvariable( "last_quarter", { to: form_date( last_quarter ) } );
var last_year = new Date( today.getFullYear() - 1, today.getMonth(), today.getDate() );
kme.setvariable( "last_year", { to: form_date( last_year ) } );
})();
Stop macro and notify on failure.
Insert Text by Pasting
Last Week: [[%Variable%last_week%]]%LineFeed%
Last Month: [[%Variable%last_month%]]%LineFeed%
Three Months Ago:[[%Variable%last_quarter%]]%LineFeed%
One Year Ago:[[%Variable%last_year%]]%LineFeed%