I am seeking a way to start with a date in a specific format, call it, 2017-02-08. I am not stuck on the year-month-day format at this point but it is similar to an example I have using Typinator and JavaScript. Typinator does a great job tracking dates for me. But those dates are preset. This one I want to start and end with a selected text date.
This date value will already be on a document. To begin the macro I will highlight the date and …
What I want is to calculate from that past (selected) date until today and have the results paste back as or similar to:
“From 2017-02-08 it has been 35 days as of Wed. March 15, 2017.” here assuming I did this on that later date.
This is for tracking progress notes in several files. I think it will be useful when I enter some notes on a date to later be able to review progress in my notes and have a macro tell me how long it has been sitting there - for whatever reason, closed, side tracked, etc.
I looked for a date item in the KM macros but did not find one. I looked and there are several date calculation threads on this forum, none of which appeared simple enough to easily grasp for this purpose.
The example I took from my Typinator macro looks like this:
function expand(dateParameter, context) { // – parameter: yyyy-mm-dd
_ var today = new Date()_
_ today.setHours(0)_
_ today.setMinutes(0)_
_ today.setSeconds(0)_
_ var eventDate = new Date(dateParameter)_
_ var sinceUntil = eventDate > today ? 'until ’ : ‘since’_
_ var mSecPerDay=10006060*24_
_ var diffMsec = Math.abs(today-eventDate); // difference in milliseconds_
_ var diffDays = Math.round(diffMsec/mSecPerDay)_
_ res1 = diffDays < 10 ? ‘0’ + diffDays : diffDays_
_ return “{{refDate=” + dateParameter + “}}” + res1 + " days " + sinceUntil_
}
I am not skilled enough to understand how to tweak this into what I am asking for. I looks like if I set the clipboard value (the date) to dateParameter as a variable and simply run this script, it should do. Will play with it a while. Still, it never hurts to ask in case I am wasting my time.
Thanks for any help.