addMinutes gives a date & time in the year 0014

Hello everyone

I am trying to write a simple script that will add a certain amount of minutes to a time stamp. This is intended to show what time a part will be completed, by adding its average cycle time to the time stamp of when the cycle started. I figured an addMinutes function would be a slick way to do this.

When I write my code, it gives an output with accurate time, but the date is askew. Here is my code:

dateFormat(addMinutes(toDate({[.]T_Stamp-Start}), {[.]PalletCycleTime}), “MM-dd-yyyy HH:mm:ss”)

[.]T_Stamp-Start is a string formatted tag which is the timestamp of when the cycle starts, configured in the “MM-dd-yyyy HH:mm:ss” format

[.]PalletCycleTime is an int formatted memory tag @ the moment, but will become an SQL query when the logic behaves. its created as an INT as that is what addMinutes() called out.

the scripting works (or at least does not create an null) and the time is spot on. The output date always shows up as 09-09-0014.

For example:

  • T_Stamp-Start = 08-15-2019 9:15:33
  • PalletCycleTime = 11
  • output of script: 09-09-0014 9:26:33

ive tried all kinds of formatting, eventChange scripting vs expression tags, all with no luck. Any Ideas? Any more information needed?


Try putting the year first in T_Stamp-Start.

To expand a bit, the format you are using is not a supported one for toDate():

Well, it is, but since you are using dashes in the date, it assumes the year is first.

  • You can put the year first, as was suggested (and introduce ISO 8601 to your friends and neighbors).
  • You can replace the dashes with slashes, which is a supported format.
  • You can script script something that will give a valid date:
from java.text import SimpleDateFormat

dateIn = '08-15-2019 14:15:30'

inputFormat=SimpleDateFormat('MM-dd-yyyy HH:mm:ss') # Must match the format of the input string

dateOut = SimpleDateFormat.parse(inputFormat,dateIn)

print dateOut

I will also suggest keeping things in an ISO format. If you really need the MM-dd-YYYY format for visuals, then keep it in a separate tag from your calculations.

1 Like

You guys are awesome! I flipped the year first for all of my date snags & calculations, and now everything is behaving as it should. Phew!

Ill rock ISO 8601 & spread the good word. Im back to configuring! Thanks again for the continued support guys.