cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Trouble calculating time and days between timeStamps in Workflow

Ben_A
10-Marble

Trouble calculating time and days between timeStamps in Workflow

I'm having trouble calculating the time (hours) and days between two dates Windchill provides (created and last modified) on a document. Google searching for Java examples results in tons of ideas but I haven't been able to get any to work. I think my problem is in how the stamps are stored or the format of the stored stamps. The log outputs look good but the math fails.

 

Here is what I have so far. The math function fails with: error: bad operand types for binary operator '-'.

My Workflow code:

 

 

 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("thePersistInfo.createStamp", "thePersistInfo.modifyStamp");

Object CreateStamp = obj.get("thePersistInfo.createStamp");
Object ModifiedStamp = obj.get("thePersistInfo.modifyStamp");

System.out.println("Create Stamp: " + CreateStamp);
System.out.println("Modified Stamp: " + ModifiedStamp);

//java.time.LocalDateTime hours = Math.abs((ModifiedStamp - CreateStamp)/(1000*60));

//System.out.println("Hours between: " + hours);

//Outputs to BackgrounMethodServer:
//2023-11-29 16:12:53,387 INFO  [WfUserWorkQueue.PoolQueueThread-42] wt.system.out Administrator - Create Stamp: 2023-11-27 23:41:35.0
//2023-11-29 16:12:53,391 INFO  [WfUserWorkQueue.PoolQueueThread-42] wt.system.out Administrator - Modified Stamp: 2023-11-29 19:08:43.0

 

 

 

 

 

ACCEPTED SOLUTION

Accepted Solutions
Fadel
22-Sapphire I
(To:Ben_A)

try something like below it should get age in Miliseconds  , you can then do the math and convert to minutes or hours 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("thePersistInfo.createStamp", "thePersistInfo.modifyStamp");

Object CreateStamp = obj.get("thePersistInfo.createStamp");
Object ModifiedStamp = obj.get("thePersistInfo.modifyStamp");

java.util.Date DCreateStamp=(java.util.Date)CreateStamp;
java.util.Date DMreateStamp=(java.util.Date)ModifiedStamp ;

System.out.println("Create Stamp: " + CreateStamp);

 


System.out.println("Modified Stamp: " + ModifiedStamp);

long C= (DCreateStamp.getTime() );
long M=(DMreateStamp.getTime() );
long AgeinMSec=M-C;

System.out.println("Age: " + AgeinMSec);

 

 

 

------------------ MS LOG---------------------

2023-11-30 02:00:28,579 INFO [WfUserWorkQueue.PoolQueueThread] wt.system.out Administrator - Create Stamp: 2022-02-04 09:34:05.0
2023-11-30 02:00:28,579 INFO [WfUserWorkQueue.PoolQueueThread] wt.system.out Administrator - Modified Stamp: 2022-02-04 09:35:40.0
2023-11-30 02:00:28,579 INFO [WfUserWorkQueue.PoolQueueThread] wt.system.out Administrator - Age: 95000

 

 

Fede

View solution in original post

1 REPLY 1
Fadel
22-Sapphire I
(To:Ben_A)

try something like below it should get age in Miliseconds  , you can then do the math and convert to minutes or hours 

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
obj.load("thePersistInfo.createStamp", "thePersistInfo.modifyStamp");

Object CreateStamp = obj.get("thePersistInfo.createStamp");
Object ModifiedStamp = obj.get("thePersistInfo.modifyStamp");

java.util.Date DCreateStamp=(java.util.Date)CreateStamp;
java.util.Date DMreateStamp=(java.util.Date)ModifiedStamp ;

System.out.println("Create Stamp: " + CreateStamp);

 


System.out.println("Modified Stamp: " + ModifiedStamp);

long C= (DCreateStamp.getTime() );
long M=(DMreateStamp.getTime() );
long AgeinMSec=M-C;

System.out.println("Age: " + AgeinMSec);

 

 

 

------------------ MS LOG---------------------

2023-11-30 02:00:28,579 INFO [WfUserWorkQueue.PoolQueueThread] wt.system.out Administrator - Create Stamp: 2022-02-04 09:34:05.0
2023-11-30 02:00:28,579 INFO [WfUserWorkQueue.PoolQueueThread] wt.system.out Administrator - Modified Stamp: 2022-02-04 09:35:40.0
2023-11-30 02:00:28,579 INFO [WfUserWorkQueue.PoolQueueThread] wt.system.out Administrator - Age: 95000

 

 

Fede
Announcements


Top Tags