with the help of forum members ,i am now using the below code to increment “1” to a custom field using a button
my question is . what if i want to increment a day , to an existing date , is this achievable ?
i tried different things and realized that a static value wouldn’t work, as not all month are the same number of days …
and so is there some prexisiting function in TW that can manage this calculation .
also on a side note , is there also something that would do the calculations skipping week ends, so something ala excels networkdays formula ?
You should search for ParseDate (another brilliant tool by @EricShulman) in this forum.
One solution to add days to a date is to convert it to Unix date format beforehand, then add the right amount of seconds, and convert the result back to the original format.
Also, note that “Unixtime” is specified in milliseconds. Thus, you need to multiply “the right amount of seconds” by 1000 when adding to the Unixtime value before converting back to formatted date/time text.
define variable before, for example with next wednesday’s date
define variable timestamp as before converted to Unix date
define variable oneday as 1 day in milliseconds
for after, it’s a little bit tricky: first compute values of 1, 2 and 3 days in milliseconds, then add timestamp to each value and convert back to TiddlyWiki’s native date format. Then filter these 3 values: get their “day of week number”, and keep only those before saturday. Lastly, remove every remaining value but the first one.
You can test this code by changing the 17 part of before definition.
The days[] operator requires input in the form of a TWCore 17-digit date that is stored in a specified tiddler field (e.g., modified), while @tw-FRed’s solution uses date values that are held in variables without using any tiddlers.
However, there is one small bug in your implementation: when using the unixtime[...format...] filter operator, the format needs to convert the timestamp to a [UTC] date output in order to avoid applying an implicit adjustment for local timezone offset.
There are two ways to achieve this:
A) Use a variable to add the [UTC] prefix to the unixtime filter operand, like this:
note: the format variable is needed because you can’t use a value containing square brackets as as a literal filter operand
OR
B) use the parsedate:unixtime[] filter operator (with no format operand), which applies a default output format of [UTC]YYYY0MM0DD0hh0mm0ss0XXX without needing to specify a filter operand at all, like this:
sorry for coming back to this again , but i have a new requirement, i need to increment more than “1” , the script seems to handle 1 or 2 increments but not more, before starting to count weekends back again .