- This topic has 4 replies, 4 voices, and was last updated 11 months, 1 week ago by Ian Shorthose.
- December 22, 2021 at 12:27 pm #20462RangaParticipantKarma: 17Rank: Padawan
how do you calculate time elapsed between two datesDecember 22, 2021 at 12:46 pm #20463PLCGuruKeymaster
Hi Ranga and welcome to the forums.
Since you did not specify the type of controller you’re using, I’m going to assume it is a ControlLogix platform of controller. In this case, you can use the GSV (Get System Value) instruction to get the current date/time from your CPU. You can parameterize the GSV as follows:
Class Name: WallClockTime
Attribute Name: LocalDateTime
The Get_Date_Time tag is setup by creating an array of DINT with each element of the array holding a corresponding portion of the date/time. Below is the actual array assignment:
DINT = Year
DINT = Month (1..12)
DINT = Day (1..31)
DINT = Hour (0..23)
DINT = Minute (0..59)
DINT = Seconds (0..59)
DINT = Microseconds (0..999,999)
Once you have the tag setup and the GSV parameterized and added to your logic to execute every scan you can build the additional logic you’ll need to grab the time stamps. This could get tricky when your dates span different months, but hopefully this will get you started in the right direction.
If you provide more information, perhaps we can get more community involvement to help solve your issue.
CheersDecember 22, 2021 at 5:21 pm #20471mark88590ParticipantKarma: 20Rank: Padawan
If it is AB we are discussing there is a neat AOI you can use to calculate time between dates. It is in the sample code library. Just search something like “time between”. It should be one of the top hits from the search.December 23, 2021 at 10:02 am #20496RangaParticipantKarma: 17Rank: Padawan
It is an AB controller. i need to set a reminder to replace UPS batteries after every 2 years. thanks for the suggestions. i will try them and give feedback once i get back to office early next year.
Cheers. A happy Festive season.December 23, 2021 at 10:12 am #20497Ian ShorthoseParticipantKarma: 21Rank: Padawan
Used that AOI it’s easy to implement and does the job. Search for “Elasped Time Add-on Instruction” (Yes, Elapsed is spelled wrong ?)
- You must be logged in to reply to this topic.