# Transform rule to get days difference between today's date and past date

**URL:** <https://developer.sailpoint.com/discuss/t/transform-rule-to-get-days-difference-between-todays-date-and-past-date/165352>\
**Category:** SHF Community Knowledge Base\
**Tags:** identity-security-cloud, transforms, rules\
**Created:** [August 7, 2025, 1:33pm UTC](https://developer.sailpoint.com/discuss/t/transform-rule-to-get-days-difference-between-todays-date-and-past-date/165352 "2025-08-07T13:33:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpatel](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@cpatel](https://developer.sailpoint.com/discuss/u/cpatel)\
**Post date:** [August 7, 2025, 1:33pm UTC](https://developer.sailpoint.com/discuss/t/transform-rule-to-get-days-difference-between-todays-date-and-past-date/165352/1 "2025-08-07T13:33:35Z")

</div>

# Problem

We often get use cases where we want the difference between today’s date and a past or future date. Current transforms in IdentityNow do not give us the difference between 2 dates in days. There are workarounds to convert date into epoch, calculate the difference, and convert that number back into days, but those are hacky and not clean.

# Diagnosis

The purpose of this knowledge article is not just to share this simple rule but also to start a conversation about whether Sailpoint Professional Services should just build a standard rule for all tenants that can be used by all customers so that all those repetitive hacky workarounds are not needed.

# Solution

> ```java
> <?xml version='1.0' encoding='UTF-8'?>
> <!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
> <Rule name="DaysDifferenceGeneric" type="Transform">
> <Description>Gets date input from transform and returns days diffrence to today's date</Description>
> <Source><![CDATA[
> import java.util.Date;
> import sailpoint.object.Identity;
> import java.text.ParseException;
> import java.text.SimpleDateFormat;
> 
> log.error("Inside-DaysDifferenceGeneric-rule: started");
> 
> String lastLogin=date;
> if(lastLogin == null) {
> log.error("Inside-DaysDifferenceGeneric-rule: lastlogin is null");
> return null;
> }
> log.error("Inside-DaysDifferenceGeneric-rule: lastlogin value in string "+lastLogin );
> 
> try {
> // Define the date format
> SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
> // Parse the input string into a Date object
> Date staticDate = isoFormat.parse(lastLogin);
> log.error("Inside-DaysDifferenceGeneric-rule: lastlogin value in date format "+staticDate );
> // Current date
> Date currentDate = new Date();
> 
> // Calculate the difference in milliseconds
> long diffInMillies = Math.abs(currentDate.getTime() - staticDate.getTime());
> 
> // Calculate different
> // Calculate different time units
> long diffInDays = diffInMillies / (1000 * 60 * 60 * 24);
> return String.valueOf(diffInDays);
> 
> } catch (ParseException e) {
> throw new Exception("Invalid date format. Please use ISO 8601 format.");
> }
> ]]></Source>
> </Rule>
> 
> ```

---

<div class="post-metadata">

**Author:** ![sup3rmark](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/sup3rmark/32/36229_2.png) [@sup3rmark](https://developer.sailpoint.com/discuss/u/sup3rmark)\
**Post date:** [August 7, 2025, 4:02pm UTC](https://developer.sailpoint.com/discuss/t/transform-rule-to-get-days-difference-between-todays-date-and-past-date/165352/2 "2025-08-07T16:02:35Z")

</div>

I don’t know, I think [my transform logic](https://developer.sailpoint.com/discuss/t/transform-find-users-last-activity-date-find-latest-date-in-array/34841) to handle this is pretty clean 😛 (converting the date to `yyMMddHH` format and then using Velocity to do the math)…

That said, I have a submitted [Idea in the Ideas Portal](https://ideas.sailpoint.com/ideas/GOV-I-4029) to have the Velocity `dateTool` functions (and `numberTool` functions) added to Transforms. These are already in play in email templates, but not in Transforms. Please throw an upvote on that Idea to simplify this process in Transforms directly.

But nice work on the Rule as another way to solve this problem!

---

<div class="post-metadata">

**Author:** ![cpatel](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@cpatel](https://developer.sailpoint.com/discuss/u/cpatel)\
**Post date:** [August 11, 2025, 4:31am UTC](https://developer.sailpoint.com/discuss/t/transform-rule-to-get-days-difference-between-todays-date-and-past-date/165352/3 "2025-08-11T04:31:55Z")

</div>

Getting things in product takes time, that is the reason it is good to have standard/generic rule deployed for all tenants so everyone can start using it.  
I assume deploying rule would not be as difficult as building new product functionality
