Generating a specific DATE_AND_TIME value

2020-01-02
2020-01-09
  • Tim.Manning - 2020-01-02

    I need to be able to generate a specific DATE_AND_TIME value. The user will input the Month, Day and Hour as integers, and the program will work out the Year.

    I am having trouble figuring out how to do this. I tried generating a string, and then converting the string to a DATE_AND_TIME variable. There appears to be a STRING_TO_DT function, but it does not seem to work, and I see nothing in the help files that actually references it.

    Any ideas on how to do this would be great.

     
  • Anonymous - 2020-01-03

    Originally created by: ph0010421

    Hello Tim
    Add the library DTUtil. Some good stuff in there.
    Or before I found this library, I wrote this FB...(PLCOpenImport)
    ph

    PLC090419_1.xml [8.56 KiB]

     
  • Tim.Manning - 2020-01-03

    Thanks. I actually got my code to work just now. The STRING_TO_DT function does work, you just have to make sure the string is formed properly, and includes all the right things. I was missing the 'DT#' at the beginning of the string.

    I will take a look at what you sent and the DTUtil library.

     
  • RoryLDM - 2020-01-09

    This is the library "CAA DTUtil Extern" correct?

    I will also have to look at that library, thanks. What I currently do is use the CONCAT function to add the appropriate formatting to various strings before converting them. I can never trust people to enter the correct format if it includes things like t# even if the dialogue windows informs them of the correct formatting they can't be trusted.

    Edit: Ah yes I already had the library installed because the 3S library "Time and Date 3.5.7.0" installs it. It looks like the functions DTConcat and DateConcat and really all of the rest as well are super helpful. I can testify that the function blocks

    GetTimeZoneInformation
    SetTimeZoneInformation
    GetDateAndTime
    SetDateAndTime

    Are also super useful for setting the time and date from within the visualizations rather than having to set it on the OS.

     

Log in to post a comment.