Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Schlau Lösung um anhand der Systemzeit eine neue Datei anzulegen

2022-11-15
2022-11-18
  • pumpenheinrich - 2022-11-15

    Guten Tag,
    ich habe einen Logger ertstellt welcher eine Datei: z.B. Logger_202211 erstellt und beschreibt. Nun möchte ich gerne das automatisch jeden Monat eine neue Loggerdatei: z.B. Logger_202212 erstellt wird. Gibt es eine elegante Lösung wie ich den aktuellen Dateiname auslesen kann und mit dem String für das aktuelle Jahr (sYear) und aktuellen Monat (sMonth) vergleichen kann?

    VG PumpenHeinrich

     
  • ignat - 2022-11-18

    Hi, the simplest would be to check whether the file with such name already existing or not.

    To combine file name with actual date/time you could use OSCAT or STRING library functions.
    Z.B, i have smth like this:

        sTimeString := '';
        sTimeString :=  DT_TO_STRING(ProcessReport.dtStartedAt);
        sTimeString := DELETE(sTimeString, 4, 0);
        sTimeString := REPLACE(sTimeString, '_', 1, 5);
        sTimeString := REPLACE(sTimeString, '_', 1, 8);
        sTimeString := REPLACE(sTimeString, '_', 1, 11);
        sTimeString := REPLACE(sTimeString, '_', 1, 14);
        sTimeString := REPLACE(sTimeString, '_', 1, 17);
        sFileName := CONCAT(FILENAME_PREFIX, sTimeString);
        sFileName := CONCAT(sFileName, FILENAME_END);
    
     

Log in to post a comment.