[NEWSboard IBMi Forum]

Thema: %time() ??

  1. #1
    Registriert seit
    Jul 2002
    Beiträge
    43

    Question %time() ??

    Hallo Forum,

    ich habe in RPGIV in free-code folgende Anweisung erstellt:
    /free
    prdate = %date();
    prtime = %time();
    /end-free
    Die Felder prdate und prtime sind in einer extern beschriebenen Datei definiert:
    A PRDATE L
    A PRTIME Z
    Bei der Umwandlung des RPG-Programms erhalte ich folgende Fehlermeldung:
    *RNF7416 30 1 Die Arten der Operanden auf der rechten und linken Seite des Ausdrucks in der Operation EVAL stimmen nicht überein. //bezieht sich auf die Zeile 2 (PRTIME)
    Was mache ich falsch?
    Wie definiere ich das Feld richtig, damit ich die Systemzeit mit diesem Befehl ermitteln kann ?

    Danke im voraus für Eure Hilfe, Marc

  2. #2
    Registriert seit
    Aug 2001
    Beiträge
    2.873

    Post

    Hallo Marc,

    die Definition "Z" in deinem DDS ist die Definition für eine Zeit-Marke und nicht für ein Zeit-Feld.
    Definition für ein Zeit-Feld ist "T".

    Willst Du ein Zeitmarken-Feld füllen, benötigst Du die Built-in-Function %Timestamp().

    Birgitta
    Birgitta Hauser

    Anwendungsmodernisierung, Beratung, Schulungen, Programmierung im Bereich RPG, SQL und Datenbank
    IBM Champion seit 2020 - 4. Jahr in Folge
    Birgitta Hauser - Modernization - Education - Consulting on IBM i

  3. #3
    Registriert seit
    May 2002
    Beiträge
    2.642
    Hallo MARC,
    vielleich hilft dies:

    Date and Time Functions in V5R1 RPG

    Hey, Ted:
    Here's a snippet of RPG code that loads timestamp variables from legacy date formats and date/time variables.


    It shows how to use three new built-in functions to make date/time comparisons easier than they used to be.
    The problem arises when dates and times are stored in separate fields and must be compared.
    Maybe the dates and times are in fields of the date and time data types, but in many databases, they're stored in plain old alpha or numeric fields.
    To compare two date/time combinations requires logic like the following example:
    * is job-on date/time before scheduled date/time?
    C if (job_on_date < sched_date) or
    C (job_on_date = sched_date and
    C job_on_time < sched_time)

    This is cumbersome, and I have seen many places where the comparison was done incorrectly.
    I convert all date and time pairs to timestamps before comparison. The %date, %time, and %timestamp built-in functions, introduced in V5R1, simplify such conversions.
    Use this code to convert a legacy date and time to a timestamp:
    H DATFMT(*ISO) TIMFMT(*ISO)
    D legacy_time s 6p 0 inz(073403)
    * HH MM SS
    D legacy_date s 6p 0 inz(071802)
    * MM DD YY
    D legacy_stamp s z inz
    /free
    legacy_stamp = %timestamp(
    %char(%date(legacy_date:*MDY)) + '-' +
    %char(%time(legacy_time:*hms)) + '.000000');
    /end-free

    Use this code to convert date and time data types to a timestamp:
    H DATFMT(*ISO) TIMFMT(*ISO)
    D defined_time s t inz
    D defined_date s d inz
    D defined_stamp s z inz
    /free
    defined_stamp = %timestamp(
    %char(defined_date) + '-' +
    %char(defined_time) + '.000000');
    /end-free

    gruss TARASIK

    [Dieser Beitrag wurde von TARASIK am 11. April 2003 editiert.]

  4. #4
    Registriert seit
    Jul 2002
    Beiträge
    43

    Smile


    D A N K E Euch beiden !

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • You may not post attachments
  • You may not edit your posts
  •