Date Counter for Documents
Asked by Martin James:

I'm investigating to find out if it is possible to create a date counter for Confluence for when a page has been created and modified (see example below). We are on a tight budget so we can't fork out money to pay for such feature. I was wondering if it possible to achieve this with User Macro?

<br />

PageCounter.jpg  
[](https://community.atlassian.com/t5/Confluence-questions/Date-Counter-for-Documents/qaq-p/380405?attachment-id=3053){#link_1186af6b6fa51a}  
[](/tnckb94959/attachments/tnckb94959/confluence-questions/64316/1/PageCounter.jpg){#display_1186af6b6fa51a_0}


Answers:
author: Stephen Deutsch
body: Obviously the Archiving Plugin would be more robust, but here's a user macro that would fulfill your requirements:

```
## @param LimitDays:title=# of days until outdated|required=true|type=int|default=30|desc=This is the number of days until the info box will show as a warning box#set ( $limitDays = 30)#set ( $daysSinceCreated = ($action.dateFormatter.calendar.timeInMillis - $content.creationDate.time ) / (1000*60*60*24) )#set ( $daysSinceLastModified = ($action.dateFormatter.calendar.timeInMillis - $content.lastModificationDate.time ) / (1000*60*60*24) )#set ( $limitDays = $generalUtil.convertToInteger($paramLimitDays).intValue() )#if ( $generalUtil.isInLastDays($content.lastModificationDate, $limitDays) )  #set ( $macroType = "info" )#else  #set ( $macroType = "warning")#end#if ( $daysSinceCreated &gt;= 21 )  #set ( $sinceCreatedString = ($daysSinceCreated / 7) + " weeks" )#else  #set ( $sinceCreatedString = $daysSinceCreated + " days" )#end#if ( $daysSinceLastModified &gt;= 21 )  #set ( $sinceLastModifiedString = ($daysSinceLastModified / 7) + " weeks" )#else  #set ( $sinceLastModifiedString = $daysSinceLastModified + " days" )#end&lt;ac:structured-macro ac:name="$macroType"&gt;  &lt;ac:rich-text-body&gt;    &lt;p&gt;      &lt;span&gt;This page was created &lt;/span&gt;&lt;b&gt;$sinceCreatedString&lt;/b&gt;&lt;span&gt; ago. &lt;/span&gt;    &lt;/p&gt;	&lt;p&gt;      &lt;span&gt;This page hasn&amp;#39;t been updated for &lt;/span&gt;&lt;b&gt;$sinceLastModifiedString&lt;/b&gt;&lt;span&gt;. &lt;/span&gt;    &lt;/p&gt;  &lt;/ac:rich-text-body&gt;&lt;/ac:structured-macro&gt;
```

comments: author: Stephen Deutsch
body: Right now the default # of days is 30, but you can change that in lines 1 and 2 if you wish (you need to change both to the same value).


author: Martin James
body: This is absolutely spot on. I am really grateful of the time you have spent putting this together for me. I still have such a long way to go before I master velocity. Where did you learn all this from?


author: Stephen Deutsch
body: Basically a ton of trial and error and looking at the work that others have done, specifically the other prolific user macro writers:

Andrew Frayling  
Matthew Horn  
Steve Goldberg  
Davin Studer  
Sandro Herrmann  
(apologies if I missed someone)

Beyond this, take a look at these pages:

<https://confluence.atlassian.com/doc/user-macro-template-syntax-223906130.html>

<https://developer.atlassian.com/confdev/development-resources/confluence-architecture/confluence-internals/velocity-template-overview/confluence-objects-accessible-from-velocity>

Take a look at the Javadoc for the objects accessible in Velocity (and some that aren't, since it's possible to import some extra classes), including Page/ContentEntityObject.

Also, it's good to look at the documentation for version 1.6 of Velocity (the one that's included in most versions of Confluence):

<http://velocity.apache.org/engine/1.6/user-guide.html>

For some extra ideas, I have a bunch of user macros in my Bitbucket repository:

<https://bitbucket.org/stephendeutsch/confluence-user-macros>

They're getting a bit old, but you should be able to get at least a few ideas :smile:


author: Midori
body: I don't know about your budget, but the [Archiving Plugin](https://marketplace.atlassian.com/plugins/com.midori.confluence.plugin.archiving/server/overview) has this feature.

46dfb7cd-76f7-4117-b269-2f23361fc426.png  
[](https://community.atlassian.com/t5/Confluence-questions/Date-Counter-for-Documents/qaq-p/380405?attachment-id=2765){#link_1186af84b81056}  
[](/tnckb94959/attachments/tnckb94959/confluence-questions/64319/1/46dfb7cd-76f7-4117-b269-2f23361fc426.png){#display_1186af84b81056_0}

comments: author: Martin James
body: Thanks for the suggestion. I did demo this a while ago and it seems really good. I would definatly look at this in the future.


author: Daniel Vlad
body: Hi,

i try to create a table macro in which two current report values can be displayed together.  
"Metadata report" and "View of contributors" - see attachmend.

![2018-02-02 Confluence01.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/13868i9830F612C29DC59A/image-size/large?v=v2&px=999 "2018-02-02 Confluence01.jpg")  
Unfortunately, I do not succeed. I also have to admit that my programming experience is not very good.

The table should have 4 columns.  
Page, process owner (metadata "prozessver"), date of last modify, counter "Last change before 30 days".

Can someone help me or give a tip on this?

I have tried this code, without success : (

```
## @param daysSinceLastModified:title=# of days until outdated|required=true|type=int|default=30|desc=This is the number of days until the page was modified

#set ( $daysSinceLastModified = ($action.dateFormatter.calendar.timeInMillis - $content.lastModificationDate.time ) / (1000*60*60*24) )
#set ( $descendantPages = $pageManager.getDescendents($content) )
#set( $prozessverantwortlicher = $metadataService.getMetadataValue(prozessver ) $!value

<table>
 <tr>
 <th>Page</th>
 <th>Ge?ndert von</th>
 <th>?nderungsdatum</th>
 <th>Ge?ndert seit < 7d?</th>
 </tr>
 #foreach ( $page in $descendantPages )
 <tr>
 <td><a href="${req.contextPath}$page.urlPath"> $page.title </a></td>
 <td> $prozessverantwortlicher </td>
 <td> $action.dateFormatter.format($page.lastModificationDate) </td>
 <td> $daysSinceLastModified </td>
 </tr>
 #end
</table>
```


author: Martin James
body: I would say give it 21 days which is 3 weeks. Thanks for your time helping me with this :smile:

I have been trying to find a solution for a while now but everything I try doesn't seem to work.


author: Stephen Deutsch
body: Seems possible. What should the limit be for when a # of days is displayed as # of weeks? Above it shows 9 days ago, which is more than 1 week. Would the cutoff be at 2 weeks or something?


Tags: confluence-administration

user-macro