On Thursday, August 27, 2020 at 12:04:00 PM UTC-7, Ed Heil wrote:
>
> I'm interested in populating a field on a tiddler with the "day number" 
> (Jan 1 = 1, Dec 31 = 365 or 366).  There doesn't seem to be an option in 
> the now macro which will give me that number, unless I'm missing 
> something.  
> Of course, if there's some way to get a day number out of the now macro, I 
> wouldn't have to worry about it. :)
>

Here's a macro that calculates the day number (1 through 365/366) and a 
$button that stores the result in a tiddler field:

\define getDay()
\whitespace trim
<$vars yyyy=<<now "YYYY">> mm=<<now "MM">> dd=<<now "DD">>>
<$set name="dpm" filter="[<yyyy>divide[4]split[.]count[]match[1]]"
     value="31 29 31 30 31 30 31 31 30 31 30 31" emptyValue="31 28 31 30 31 
30 31 31 30 31 30 31">
{{{ [enlist:raw<dpm>first<mm>butlast[]sum[]add<dd>] }}}
\end

<$button> set days
<$wikify name="days" text=<<getDay>>>
<$action-setfield days=<<days>> />
</$wikify>
</$button>

The getDay() macro does this:
* \whitespace trim removes all whitespace from the macro output
* $vars gets the current year (YYYY), month (MM) and date (DD)
* $set name="dpm" (days per month) determines if the year is a leap year 
(i.e., evenly divisible by 4) and then defines a list of days per month
* the inline filter enlists the days per month (using :raw to include 
duplicate values)
* then it trims the list to only include the months up to, but not 
including, the current month
* and then sums those numbers and adds the date for the current month

The $button does this:
* $wikify takes the getDay() macro and converts it's output to plain text
* $action-setfield saves the plain text value to the "days" field of the 
current tiddler

enjoy,
-e

-- 
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 tiddlywiki+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/37fb371d-4468-45c1-8b9b-6bff1cc4e456o%40googlegroups.com.

Reply via email to