How to change the date format within a PocketQuery Template
If you are working with a SQL Datasource without a Converter, the timestamps that are retrieved from the database can very easily be formatted within a custom Template. We will use the
$dateFormatter, that is accessible from within every custom Template.
Start by creating a new Template at the PocketQuery administration. You can insert the code for the default tempate using the text link at the top right "Add default template".
Next, decide for which column you will need to change the format. We can use the implicit velocity variable $velocityCount here, that is present within every loop and starts counting at 1. So if the dates are within the 5th column, we can reformat them with this template:
<table class="aui confluenceTable pocketquery-table"> <thead> <tr> #foreach ($column in $columns) <th>$!column</th> #end </tr> </thead> <tbody> #foreach ($row in $result) <tr> #foreach ($column in $row) ##### here starts the custom part #if ($velocityCount == 5) <td>$dateFormatter.formatGivenString("yyyy-mm-dd HH:MM", $column)</td> #else <td>$!column</td> #end ##### here the custom part ends #end </tr> #end </tbody> </table>
Make sure to assign the custom Template to your Query.
Note: If you use a Converter on your Query, you will need to do the formatting in there.