Troubleshooting .NET System.DateTime in Wonderware System Platform

Question:

Hello everyone, I am a newcomer to programming in .NET on the Wonderware System Platform, and I am facing challenges with a .NET function. My goal is to initialize a .NET structure to retrieve the current date and time of the system where the Automated Object is operating. However, I am encountering an error message stating "Date._ErrorReport:Script Date (Execute). Unknown Property:Today..." The objective is to maintain a consistent system date that will be synchronized with a PLC clock. I have provided the code I have created below: ``` DIM DOB as System.DateTime; DOB = new System.DateTime; Me.DateTime = System.DateTime.Today; //Copy the date time to Me.Datetime Me.DateTimeHour = System.DateTime.Hour; Me.DateTimeMin = System.DateTime.Minute; Me.DateTimeSec = System.DateTime.Second; ``` I am unsure why the code is not working as expected, especially since the MSDN site indicates that ".Today" is a property. I would prefer to stick to .NET programming rather than using InTouch variables like $Month, $Day, $Year. Any assistance on this matter would be greatly appreciated. Thank you!

Top Replies

Learn how we synchronize System date and time with a Master Date and Time variable for PLC applications. By utilizing the MyPlatform.Scheduler.ScanTime as our reference point, we extract and convert the data into a format suitable for PLC usage. This process involves shifting the values to their respective positions and converting them to decimal for integration into PLC systems. Regular comparisons are conducted between the PLC Time and the timestamp generated by this script to ensure synchronization. Don't forget to enable synchronization in the PLC CPU function block within the PLC code.

Thank you RheinhardtP for your help! I appreciate the solution you provided, as it seems like it would be effective for my situation. Can anyone help clarify why I am encountering the "Unknown Property..." error in the .NET code snippet shared below? The code in question is as follows: '//Start Code DIM DOB as System.DateTime; DOB = new System.DateTime; Me.DateTime = System.DateTime.Today; - I'm curious to understand why this isn't functioning as expected.

I recently revisited some code and found a better way to handle date and time. I created a User Defined Attribute (UDA) called DateTime of type Time to easily access the current time. By using the following code snippet, I was able to retrieve the time in the Time format UDA: Dim HourT as INT; Dim MinT as INT Me.DateTime = System.DateTime.Now; ' HourT = System.DateTime.Now.Hour ; MinT = System.DateTime.Now.Minute ; 'This method worked well. I did not explore datetime.today, as it was unnecessary with the above approach. This new code is much more concise than our previous version.

Thank you, RheinhardtP, for your assistance. I have written the code in the following format: DIM SystemDate AS System.DateTime; SystemDate = Platform.Scheduler.ScanTime; Me.Year = SystemDate.Year; Me.Month = SystemDate.Month; Me.Day = SystemDate.Day; Me.Hour = SystemDate.Hour; Me.Min = SystemDate.Minute; Me.Sec = SystemDate.Second; I am curious about the .NET programming conventions used by the system platform. It appears to be similar to VB.NET, but there are some differences. Can you provide any insight on this? Thank you.

Scripts are typically executed in objects within the .NET Framework 4.0. This is especially relevant if you are using the 2012 R2 operating system.

Hey there, Welcome to .NET programming on the Wonderware System Platform. You're nearly there with your code, but I think the issue might be the way you're trying to access the current date and time system properties. Instead of 'System.DateTime.Today', 'System.DateTime.Hour', 'System.DateTime.Minute', and 'System.DateTime.Second', you should instantiate a DateTime object and then use its properties to get the current date and time. You can do so as follows: ``` DIM currentTime as System.DateTime = System.DateTime.Now; Me.DateTime = currentTime.Date; Me.DateTimeHour = currentTime.Hour; Me.DateTimeMin = currentTime.Minute; Me.DateTimeSec = currentTime.Second; ``` In this amendment, System.DateTime.Now creates a new DateTime object representing the current date and time. You then use this object's properties (.Hour, .Minute, .Second) to get the current hour, minute, and second. I hope this helps you out and journey on, new programmer friend!

Hey there! It looks like you're on the right track, but the issue might be that `System.DateTime.Today` is a property that returns the current date without a time component and shouldn't be assigned to `Me.DateTime` directly if it's expecting a full DateTime object. Instead, try using `DateTime.Now`, which gives you the current date and time. Also, ensure that the properties `Me.DateTimeHour`, `Me.DateTimeMin`, and `Me.DateTimeSec` are set correctly—those should be derived from `DOB` instead. So, your initialization could look something like this: ``` DIM DOB as System.DateTime = System.DateTime.Now; Me.DateTime = DOB; Me.DateTimeHour = DOB.Hour; Me.DateTimeMin = DOB.Minute; Me.DateTimeSec = DOB.Second; ``` Give that a shot and see if it helps! Good luck!

More Replies →

Streamline Your Asset Management
See How Oxmaint Works!!

✅   Work Order Management

✅   Asset Tracking

✅   Preventive Maintenance

✅   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

To add a comment, please sign in or register if you haven't already..   

Frequently Asked Questions (FAQ)

FAQ: FAQ 1:

Answer: Question: What is the error message "Date._ErrorReport:Script Date (Execute). Unknown Property:Today" indicating in the provided .NET code snippet? Answer: The error message indicates that the property `.Today` is not recognized in the context where it is being used. It seems there is a misunderstanding in how the `System.DateTime` object is being accessed.

FAQ: FAQ 2:

Answer: Question: Why is the code snippet not working as expected when trying to retrieve the current date and time using .NET in Wonderware System Platform? Answer: The issue lies in how the `System.DateTime` object is being initialized and accessed in the code snippet. The usage of `System.DateTime.Today` to directly access the current date is incorrect.

FAQ: FAQ 3:

Answer: Question: How can I correctly retrieve and set the current date and time in .NET on the Wonderware System Platform? Answer: To retrieve the current date and time, you should initialize a new `System.DateTime` object and then access the properties `DateTime.Now` instead of `DateTime.Today` to get the current date and time.

FAQ: FAQ 4:

Answer: Question: Is it possible to synchronize the system date with a PLC clock using .NET programming in Wonderware System Platform? Answer: Yes, you can synchronize the system date with a PLC clock using .NET programming by correctly accessing the current date and time from the `System.DateTime.Now` property and implementing the synchronization

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  â†’