How to convert Date format" 6/4/2008 8:00:00AM" to only 6/4/2008

Hello Team,
I am adding Epic Schema Attribute “LAST_ACCS_DATETIME” in IIQ. The value I am getting for “LAST_ACCS_DATETIME” is like this : 6/26/2024 3:34:00PM
I want the value to be only 6/26/2024 .
I am created a customization rule

import sailpoint.object.ResourceObject;
import java.util.Date;
import java.text.SimpleDateFormat;


SimpleDateFormat iiqDateFormat = new SimpleDateFormat("MM/dd/yyyy");

if(object.getAttribute("LAST_ACCS_DATETIME") != null){
   long LAST_ACCS_DATETIME = Long.parseLong(object.getAttribute("LAST_ACCS_DATETIME"));   
 object.setAttribute("LAST_ACCS_DATETIME", iiqDateFormat.format(date));


}
   
return object;

But Getting Error Saying :The application script threw an exception: java.lang.NumberFormatException: For input string: “7/15/2022 7:25:00AM”

Can anyone help me with this?
Thank you

Hi and hello @j1241

The error you’re encountering (java.lang.NumberFormatException) is because the value you’re passing (“7/15/2022 7:25:00AM”) is a string representing a date and time, not a number. In your script, you’re trying to parse this string into a long (Long.parseLong()), which expects a numeric value, not a date-time string.

To fix this, you should treat the LAST_ACCS_DATETIME as a string, parse it into a Date object using SimpleDateFormat, and then reformat it to only keep the date part.

Maybe you can do like this:

import sailpoint.object.ResourceObject;
import java.util.Date;
import java.text.SimpleDateFormat;

SimpleDateFormat iiqDateFormat = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat inputDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ssa");

if (object.getAttribute("LAST_ACCS_DATETIME") != null) {
    String LAST_ACCS_DATETIME = object.getAttribute("LAST_ACCS_DATETIME");
    
    try {
        // Parse the input string into a Date object using the input format
        Date parsedDate = inputDateFormat.parse(LAST_ACCS_DATETIME);
        
        // Format the parsed date into the desired output format
        object.setAttribute("LAST_ACCS_DATETIME", iiqDateFormat.format(parsedDate));
    } catch (Exception e) {
        // Handle parsing error if the input string is not in the expected format
        e.printStackTrace();
    }
}

return object;

This should solve the issue, and you will get the LAST_ACCS_DATETIME in the MM/dd/yyyy format.

Regards,
Adam

3 Likes

@AdamVentum You are genius. Thank you. It worked.

1 Like

No problemo my Frend:)

3 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.