Sorry if I was unclear Saq. The macro doesn't generate the format, it 
generates the date. I need to pass <$view> a date *other than today* and 
have it apply the formatting. 

I should point out in case anyone else finds it helpful, while Jed's 
add-time.js (
http://inmysocks.tiddlyspot.com/#%24%3A%2Finmysocks%2Fmacros%2Fadd-time.js) 
is great, it didn't let me start with any other date than today, which I 
was able to tweak. This code (below) is what I'd love to add a parameter 
string to so that I can also pass it "YYYY-MM-DD". I hope that makes more 
sense. 

/*\
title: $:/stobot/macros/dateadd.js
type: application/javascript
module-type: macro

Takes a base date and adds days, months or years

\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro
*/

exports.name = "dateadd";

exports.params = [
 {name: "basedate"},
 {name: "days"},
 {name: "months"},
 {name: "years"}
];

/*
Run the macro
*/
exports.run = function(basedate, days, months, years) {
 
 //Make each date object.
 
 if (basedate === "") {
 var newdate = new Date();
 } else {
 var baseyear = basedate.substr(0,4);
 var basemonth = basedate.substr(4,2);
 var baseday = basedate.substr(6,2);
 var newdate = new Date(Number(baseyear), Number(basemonth)-1, Number(
baseday), 0, 0, 0);
 }

 var new_year = Number(newdate.getFullYear())+Number(years);
 var new_month = Number(newdate.getMonth())+Number(months);
 var new_day = Number(newdate.getDate())+Number(days);

 var output_date = new Date(new_year, new_month, new_day, 0, 0, 0);
 
 var result = (output_date.getFullYear()*10000) + ((output_date.getMonth()+1
)*100) + (output_date.getDate());

 return result;
};

})();


-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/b5c7cbd5-fdd2-4c50-88bf-ae507c9ec990%40googlegroups.com.

Reply via email to