okay, I'm trying to get the best of both worlds, i.e. using this method
(using yyyy-mm-dd to count days) and using the days operator (which
requires yyyymmdd format), so I need to use yyyymmdd format in my "due"
field, but convert it to a yyyy-mm-dd format within this jsmacro.
I though this should work:
/*\
title: $:/inmysocks/macros/day-diff2.js
type: application/javascript
module-type: macro
Takes two dates and returns their difference in days
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "day-diff2";
exports.params = [
{name: "duedate"}
];
/*
Run the macro
*/
exports.run = function(duedate) {
//Make each date object.
var date1 = new Date();
var mydate = new Date(duedate);
var year = mydate.substring(0,4);
var month = mydate.substring(4,6);
var day = mydate.substring(6,8);
var date2 = year + '-' + month + '-' + day;
//Find difference in milliseconds.
var elapsed = date2.getTime()-date1.getTime();
//Number of milliseconds in a day.
var dayMS = 86400000;
//Convert milliseconds to year months and days
var days_diff = Math.floor(elapsed/dayMS);
var result = days_diff;
return date2;
};
})();
but I get this error: Uncaught TypeError: mydate.substring is not a function
I tried using "mydate".substring(0,4); and ''mydate''.substring(0,4); after
googling the error
but that's not working either.
I realise asking for help on this is pushing the boundaries here as its not
strictly Tiddlywiki now. Maybe I should look for a javascript forum, but
I'm not sure where javascript ends and tiddlywiki begins...
thanks
--
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/a5d80e31-15fc-4cb2-aba9-9a52ef113190%40googlegroups.com.