WinCC Flexible 2007 DateTime Data Type

lendyck

Member
Join Date
Feb 2006
Location
Cambridge, Ontario
Posts
59
If anyone has any insight to offer, it would be appreciated :)

I have defined an internal tag of the DateTime data type. I want to be able to write a customized date and time to this, within a script. I'd like to keep it as this data type so I can use VBScript functions such as DateDiff.

Everything I've seen is only for reading from this data type, not for writing to it.

Thanks.
 
I've not done this in script but I have previously defined a DateTime tag in the PLC and linked it to individual tags for the year, month, day etc to manipulate it. Assuming that your using S7, have a look in the help under appendix\complex data types and you will see the structure of the DateTime format.

Nick
 
Just try a simple experiment:

if testDT is your DateTime tag, then use testDT in an outputfield with display format = Time.

Then in a script do
testDT := Now

If the output field displays something meaningful, then it seems to have gone well, and you can write to a DateTime tag with no problems.
 
Manglemender: I wanted to keep this out of the PLC and just handle it in WinCC. In S7 you can access the elements within the Date_And_Time structure, but WinCC does not allow any means to access the bytes within the data type.

JesperMP: Yes, using VB functions such as Now will write the proper information to the tag, but I want to write a customized date/time to the tag.
 
edit: If you handle the time in the PLC, then in WinCC Flex you can setup tags for the individual bytes, in stead of a DateTime type variable.

I think you should be able to build a string that contains the various parts that make up a date and time variable.

As far as I understand, VBS will follow the order and format that is setup in Windows (Regional settings ?), also I think that the list separator (again from Regional Settings) is used to distinguish between the date and the time parts.
You can try to set a string value with Now and see how it formats.
The hard part is to safeguard that noone changes any of the regional settings.

edit:
From the help text:
date literal
Any sequence of characters with a valid format that is surrounded by number signs (#). Valid formats include the date format specified by the locale settings for your code or the universal date format. For example, #12/31/99# is the date literal that represents December 31, 1999, where English-U.S. is the locale setting for your application.
In VBScript, the only recognized format is US-ENGLISH, regardless of the actual locale of the user. That is, the interpreted format is mm/dd/yyyy.

Maybe you can make a test if the format is correct with DateValue and TimeValue functions. These will raise an .err event if the format is wrong.

edit again: There is the IsDate and CDate functions. But there is no IsTime or CTime functions. I think for the time part you can safely assume that the separator is ":", so you can build the time part like this
strTime = Cstr(iHour) & ":" & Cstr(iMinute)

edit again again:
So finally you should be able to build a time_and_date string like this

strTimeDate = "#" & Cstr(iMonth) & "/" & Cstr(iDay) & "/" & Cstr(iYear) & "# " & Cstr(iHour) & ":" & Cstr(iMinute)
 
Last edited:

Similar Topics

Hey guys, I am trying to write a vb script in wincc 2007 flexible. Basically I need to have a button which is on my overview on every screen...
Replies
1
Views
1,609
I have created a faceplate like the example says, but I'm not capable to drag it from my library into my screen. I'm only having the "stop"-sign...
Replies
0
Views
2,841
Hi, I am using WinCC Flexible 2007 Hotfix 4. I have problem downloading to a TP177A touch panel. When tranferring to the device it goes through...
Replies
13
Views
5,751
Hi everyone, thank you for reading my HelpMe post. I found this site by google. //Description of the problem: I've been trying to change screens...
Replies
5
Views
2,910
Dear All, I have an application and there is a pushbutton that access on specific screen, but i want to add a password when anyone press that...
Replies
2
Views
2,462
Back
Top Bottom