java program to find timetaken for difference between processed date and received date

0
I created a SLA Task management app foe that i want to calculate the SLA timetaken for finding the difference between received date and processed date .I am using java action.I need java program to find SLA timetaken.     help please!!
asked
3 answers
2

Hey Priya, 

Think that that could be more a Java question, then a Mendix one ;-) Might I suggest you use a Mendix function in your Microflow for datetime comparisons? E.g. daysBetween(a, b). You can use this function, e.g. when creating a variable in a microflow. You can find the documentation on these functions right herehttps://docs.mendix.com/refguide/between-date-function-calls. It would be possible to return this time difference in your java action as a parameter of the JA call.

Alternatively, if you need Java: https://stackoverflow.com/questions/55779996/calculate-days-hours-and-minutes-between-two-instants this post seems to give enough options to try.

Best regards,

Wouter

 

answered
1

You can do this in a microflow with yearsBetween, daysBetween and some logic.

 

If a Java-action is not needed, don't use it. It is harder to maintain, not all Mendix Developers understand it and bugs are harder to find and fix.

answered
0
  1. import java.text.SimpleDateFormat;  
  2. import java.text.ParseException;   
  3. import java.util.Date;   
  4. class DifferenceExample1 {     
  5.     // Create function for finding difference   
  6.     static void find(String join_date, String leave_date)   
  7.     {   
  8.         // Create an instance of the SimpleDateFormat class  
  9.         SimpleDateFormat obj = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");   
  10.         // In the try block, we will try to find the difference  
  11.         try {   
  12.             // Use parse method to get date object of both dates  
  13.             Date date1 = obj.parse(join_date);   
  14.             Date date2 = obj.parse(leave_date);   
  15.             // Calucalte time difference in milliseconds   
  16.             long time_difference = date2.getTime() - date1.getTime();  
  17.             // Calucalte time difference in days  
  18.             long days_difference = (time_difference / (1000*60*60*24)) % 365;   
  19.             // Calucalte time difference in years  
  20.             long years_difference = (time_difference / (1000l*60*60*24*365));   
  21.             // Calucalte time difference in seconds  
  22.             long seconds_difference = (time_difference / 1000)% 60;   
  23.             // Calucalte time difference in minutes  
  24.             long minutes_difference = (time_difference / (1000*60)) % 60;   
  25.               
  26.             // Calucalte time difference in hours  
  27.             long hours_difference = (time_difference / (1000*60*60)) % 24;   
  28.             // Show difference in years, in days, hours, minutes, and seconds   
  29.             System.out.print(   
  30.                 "Difference "  
  31.                 + "between two dates is: ");   
  32.             System.out.println(   
  33.                 hours_difference   
  34.                 + " hours, "  
  35.                 + minutes_difference   
  36.                 + " minutes, "  
  37.                 + seconds_difference   
  38.                 + " seconds, "  
  39.                 + years_difference   
  40.                 + " years, "  
  41.                 + days_difference   
  42.                 + " days"  
  43.                 );   
  44.         }   
  45.         // Catch parse exception   
  46.         catch (ParseException excep) {   
  47.             excep.printStackTrace();   
  48.         }   
  49.     }   
  50.     // Main class  
  51.     public static void main(String[] args)   
  52.     {   
  53.         // Set values for both dates  
  54.         String join = "12-12-2018 02:11:20";   
  55.         String leave  = "1-26-2020 07:15:50";   
  56.         // Calling find() method for getting difference bwtween dates  
  57.         find(join, leave);   
  58.     }   
  59. }  

 

You can use the above code instead of start date and end date give received date and processed date 

answered