Hello Guys,

Recently working on one of my projects, I have to calculate the time difference between two dates and display on the  UI. Although there are various ways to achieve this, but to make sure that it can also be reusable, I have decided to create the grails taglib to achieve the same functionality. Below are the steps to follow.

1- Create a taglib in your project

grails create tag-lib com.dm.DateExampleTagLib

2- Use the following code to calculate time in minutes/hours/days.

3)  The above tag can be used on the UI in following way.

<DateTag:dateFromNow date=”${emp.createdDate}”></DateTag:dateFromNow>

Snap Shot: