I want to find a way of using a macro from (https://community.atlassian.com/t5/Confluence-questions/How-to-evaluate-values-on-Confluence-Page/qaq-p/331934#M56003). I don't know anything about macros.
I have created a macro in Confluence called datecountdown and copied the script into it.
When I add it to a page I get:
"<div class="aui-message info shadowed"> <p>Countdown until <strong>Feb 29, 2020: 173 days 8 hours 36 minutes 20 seconds</strong></p> </div>" rather than the number of days.
I don't know how to write macros, is there something simple a dumb user can do to add a macro to a page?
Help appreciated.
I am modifying this to just print number if days, hours and minutes,
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 14/04/2012 ## This user macro counts down the number of days until a specific date ## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY ## declare variables and initialize as java date objects with current date #set ( $endDate = $content.currentDate ) #set ( $currentDate = $content.currentDate ) ## parse endDate param to milliseconds and set as time of endDate variable $endDate.setTime($content.currentDate.parse($paramendDate)) ## now we have 2 valid java date objects to work with #if($currentDate.before($endDate)) ## currentDate is before endDate => calculate deltas #set( $delta = ($endDate.getTime() - $currentDate.getTime()) / 1000) ## calculate remaining seconds #set( $deltaSeconds = $delta % 60 ) #set( $delta = $delta / 60 ) ## calculate remaining minutes #set( $deltaMinutes = $delta % 60 ) #set( $delta = $delta / 60 ) ## calculate remaining hours #set( $deltaHours = $delta % 24 ) #set( $delta = $delta / 24 ) ## calculate remaining days #set( $deltaDays = $delta % 365 ) <div class="aui-message info shadowed"> <p>Countdown until <strong>$deltaDays days $deltaHours hours $deltaMinutes minutes</strong></p> </div> #else ## currentDate is after endDate <div class="aui-message success shadowed"> <p>Countdown to <strong>$action.dateFormatter.format($endDate)</strong> expired <strong>$generalUtil.getRelativeTime($endDate)</strong>!</p> </div> #end
Thanks, but neither response answers my question. I don't have the time to learn how to write macros, I just want to use that one to show the number of days until a date on my page. The one above simply gives me a piece of HTML, not a number.
Macro in Confluence are similar to Macro in word or excel.
Confluence provide some built-in macro, if these Macro doen't suffice our need we can create User Macro which provide little bit of programming, and if we want full control we can Java Macro code using Java API and plugin model provided my Confluence.
I have updated given HTML and it is just a number now,
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 14/04/2012 ## This user macro counts down the number of days until a specific date ## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY ## declare variables and initialize as java date objects with current date #set ( $endDate = $content.currentDate ) #set ( $currentDate = $content.currentDate ) ## parse endDate param to milliseconds and set as time of endDate variable $endDate.setTime($content.currentDate.parse($paramendDate)) ## now we have 2 valid java date objects to work with #if($currentDate.before($endDate)) ## currentDate is before endDate => calculate deltas #set( $delta = ($endDate.getTime() - $currentDate.getTime()) / 1000) ## calculate remaining days #set( $deltaDays = $delta % 365 ) $deltaDays#end
Brilliant, thank you, it now gives a number - but unfortunately an incorrect one. With and end date of 28th Feb 2020 it should give 172 days from 9th Sept, but it gives a different number every time I load the page.
@[deleted]My mistake, try this
## Macro title: Date Countdown ## Macro has a body: No ## Body processing: No macro body ## ## Developed by: Remo Siegwart ## Date created: 14/04/2012 ## This user macro counts down the number of days until a specific date ## @param endDate:title=End Date|type=date|required=true|desc=The end date. Format: mm/dd/YYYY ## declare variables and initialize as java date objects with current date #set ( $endDate = $content.currentDate ) #set ( $currentDate = $content.currentDate ) ## parse endDate param to milliseconds and set as time of endDate variable $endDate.setTime($content.currentDate.parse($paramendDate)) ## now we have 2 valid java date objects to work with #if($currentDate.before($endDate)) ## currentDate is before endDate => calculate deltas #set( $delta = ($endDate.getTime() - $currentDate.getTime()) / 1000) ## calculate remaining seconds #set( $delta = $delta / 60 ) #set( $delta = $delta / 60 ) #set( $delta = $delta / 24 ) ## calculate remaining days #set( $deltaDays = $delta % 365 ) $deltaDays #end
@[deleted]I think you should accept this answer by @DPKJ . You have currently accepted your own answer :-)
It looks like you're new here. Sign in or register to get started.