Life, the Internet, and Everything!

Tips for Using Time Stamps in ILE RPG

Timestamps in ILE RPG

Some notes regarding timestamps.

Defining a Timestamp

A timestamp is stored as a 26 character field. But, the system looks at it as a special data type and enforces the rules it has set up for timestamps.

The format for a timestamp is is YYYY-MM-DD-HH.MM.SS.XXXXXX (Year-Month-Day-Hour.Minute.Second.Milliseconds).

An example would be ‘2011-09-14-22.06.48.592000’ (Year: 2011 / Month: 09 / Day: 14 / Hour: 22 / Minute: 06 / Second: 48 / Millisecond: 592000) .

The default value for a “*blank” time stamp is ‘0001-01-01-00.00.00.000000’.

In DDS a timestamp is defined with just the field name and a ‘Z’ in the data type column.

In RPG a timestamp is defined in the ‘D’ specs as the field name plus a ‘Z’ in the Internal Data Type column.

In SQL a timestamp is defined as ‘field-name TIMESTAMP NOT NULL WITH DEFAULT’.

Working with Time Stamps

As stated, the system will choke on an incorrect timestamp when it encounters one. So, a timestamp must always be handled as a timestamp and not a character field (no *blank, no *zeros, no character values other than those listed above).

DDS will automatically load ‘0001-01-01-00.00.00.000000’ into a timestamp when a record is written and the timestamp is *blank.

To initialize and load the current timestamp value in an RPG program: TimeStamp = %timestamp()

or you can use the TIME opcode in older RPG programs.

The preceding operations will load the timestamp value, but the last 3 digits of the millisecond segment will be ‘000. To get the complete millisecond value use: exec SQL set :TimeStamp = current_timestamp;

Of course, this means the program has to be SQLRPG or SQLRPGLE. If that’s an issue, you can always create a utility program or service program that executes that SQL, and call it from other programs to get the timestamp. That way you don’t have to change the program type on countless programs. Personally, I create most of my programs as SQLRPGLE to begin with, so it’s not an issue for me.

To extract the date (as date data type) from a timestamp use: Date = %date(TimeStamp)

Remember, although the timestamp “looks” like a character field, it is really not. So, to get it into a character field, you can either to a MOVE operation or these built-in functions: Char = %char(TimeStamp). (Move operations work with any data type).

Tags: , , , , , , , , , , , ,
Previous Post

8 Secrets to Success in Life and Work

Next Post
SEO

Search Engine Spiders – Improving Results

Comments

    • Nero
    • December 15, 2013
    Reply

    What Should Be This Characters Field Of Expertise Be? The story takes place in a fictional world, but the technology is very modern like (with social structure being a mix of Victorian and Modern era).

    Anyways, the story follows an immortal bounty hunter (he’s a king from a long forgotten nation).

    Anyways, the character is generally quite absent minded. He’s a major blood knight, and is easily distracted from the main goal. He has a terrible sense of direction, and his partner has made numerous jokes about him; getting Alzheimer’s in his old age, or him getting shot in the head too many times. He’s also quite vain, for example; he wears an eye patch that he doesn’t need (he had to wear it when he lost an eye during a fight, but he has since grown a new one) because he thinks it makes him look more “badass”.

    Anyways, I thought it would be funny if I shocked readers by revealing that he was some sort of doctor or professor (his full name is Felix Larkin, what sounds better Doctor Larkin, or Professor Larkin?) in one of his past identities.
    Last two answers are douche-bags. You do realize, I meant academic doctor, right?

    View Comment
      • Admin
      • December 15, 2013
      Reply

      Felix Larkin, MD
      He used to be a proctologist . He stopped practicing because of his bad sense of direction.

      View Comment
    • Jag
    • December 26, 2013
    Reply

    What Is The Lowest Negative Number That Can Be Stored In A Double Data Type In Java? Double.MAX_VALUE and Double.MIN_VALUE returns positive max and min value. but how can i find the lowest negative value that can be stored in a Double data type.

    Thanks a lot in advance. ?

    View Comment
      • Admin
      • December 26, 2013
      Reply

      I think you are asking for the negative value with the largest magnitude? Well, java double primitive data type (not to be confused with Double object type) is a *signed* 64-bit floating point value. The first bit is a sign bit. Therefore, the largest negative value (in absolute magnitude) is:
      -Double.MAX_VALUE

      Yes, that’s right. You just put a negative sign in front of it. ?

      View Comment
    • Anonymous
    • December 28, 2013
    Reply

    Outline The Benefits Of Having A Variety Of Data Types Available To The Programmer? Can someone please outline the benefits of having a variety of data types available to the programmer in very basic detail……need answers ASAP!

    Thanks!

    View Comment
      • Admin
      • December 28, 2013
      Reply

      ???

      a programming question in psychology?

      what kind of data? actuarial? statistical? demographic?

      View Comment
    • Geni100
    • January 31, 2014
    Reply

    SQLServer Timestamp Format? I’m accessing some legacy data stored in SQL Server, and my framework is convoluting the timestamp, so that I can’t read or write to the field of type timestamp. Does anyone know the format SQLServer is looking for with a timestamp? (When I look at it in my third party tools, it just shows that it’s binary data.)

    Thanks in advance.

    View Comment
    1. Reply

      It’s dreaded timestamp in SQL server. Though the name says it is timestamp, it’s really not. So don’t do a read/write on that column. It’s a kind of rowid precisely. By definition from SQL server books:

      The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms.

      It further states Never use timestamp columns in keys, especially primary keys, because the timestamp value changes every time the row is modified.

      Hope it helps.

      View Comment
    • Ruff Ryder
    • February 20, 2014
    Reply

    Do You Think A Footballers Character Is Reflected On The Field? Or do you see them as two separate things?

    View Comment
      • Admin
      • February 20, 2014
      Reply

      I think the word “footballer” describes their character. their immage is determined by the press

      View Comment
    • Qwe
    • February 26, 2014
    Reply

    Why Do We Need Structured Data Types?

    View Comment
      • Admin
      • February 26, 2014
      Reply

      Do you mean Abstract Data Types or Data Structures? I shall endeavor to provide answers to both questions.

      Data structures:
      A data stucture is a way of structuring data so that your chosen algorithm can process the data in an efficient manner, i.e., in such a way as to utilize as little storage space and execution time as possible. There are myriad ways to structure data, however, the most common method by far is the ubiquitous array. Data structures ranging from the simple to the complex are based on the node. A node is simply a collection of two sections of memory. One section of memory stores the data. The second section stores a location to another node in memory. If there isn’t another node then the node stores a NULL (nothing essentially).

      Abstract Data Types:
      Computers do not natively know how to deal with numbers. *GASP* “Blasphemy,” you say! “Computers don’t know nothing BUT numbers!” nuh uh uh… computers don’t know anything. All a computer does is deal with on and off switches, essentially. Therefore, the programmer and CPU designer must tell the computer how to deal with numbers. Integers, the set of all real numbers — i.e., -3,-2,-1,0,1,2,3, are infinite. A computer is finite. I can’t go into how a computer deals with integers exactly. I could get into the binary representation but I have a feeling that you wouldn’t know what I was talking about.

      Programmers need data types that the compiler does not offer. The compiler offers integers, floating point, characters, strings, etc. But what if the programmer wanted a data type that dealt with coordinates? He/She would simply define a class or a struct that contained data and methods to act upon and maintain that data.

      struct Point()
      {
      int X = 0;
      int Y = 0;
      } Point;

      int main()
      {
      coord = Point;
      coord.X = 200;
      coord.Y = 100;
      return 0;
      } View Comment

    • Redsatori
    • April 2, 2014
    Reply

    [PHP] How Do I Get A Week Value? I have to create an array of strings which need to be formatted like this:

    (Week number): Sat (date)

    I need to include every Saturday for the year in my list.

    I know that date(“W”) returns the ISO8601 week number.
    I also know that date(“D MjS, Y) will return the year like this: Mon Sep 12th, 2011.

    How do I go about finding each Saturday of a given year and also each Saturday’s ISO week number for my string?

    Additionally, it needs to limit this to the current year.

    View Comment
    1. Reply

      It’s fairly straight forward, if you use timestamps. As with anything with PHP, there are multiple ways of doing this. I like the simplicity of using timestamps, so I have included an example with notes here:
      http://pastebin.com/EcFB59Ki

      Cheers,
      Gitlez

      Feel free to contact me through my profile page if you have any follow up questions.

      View Comment
    • Blue
    • April 11, 2014
    Reply

    Get How Many Minutes Ago A Timestamp Was In Php? I have a TimeStamp 2011-02-04 05:05:50
    How could i find out how many minutes ago it was? Like say a timestamp was 5 mins ago, it would just echo 5.

    View Comment
    1. Reply

      Since timestamps are expressed in seconds, calculate the difference and then divide it by 60. Something like this should work:

      < ?php function time_diff($timestamp) { return floor(abs(time() - strtotime($timestamp)) / 60); } $event_date = "2011-02-05 01:45:50"; echo time_diff($event_date); ?>

      I used floor so that if the difference is, for instance, 59 seconds, the function will return 0 (it is not a whole minute). If you want to round up the minute value, replace floor() with ceil().

      View Comment
    • Anonymous
    • April 23, 2014
    Reply

    What Are The Different Data Types Supported By C++?

    View Comment
    1. Reply

      Learn the significance of each data type. A void type means “no data” or represents a generic pointer. The int type stores positive or negative whole numbers and is 16 or 32 bits long. “Float” (32 bits) represents decimal numbers with a moveable (floating) decimal point, and double is an extra precise float that’s 64 bits long. “Char” (8 bits) represents printable characters, and wchar_t can store a wide character literal. “Bool” (8 bits) denotes true or false.
      Step2Use the following syntax to declare a data type in your program as the following example shows: data type keyword, space, variable name, comma, space, other variable names, semicolon. Precede the data type keyword by a data type modifer, if necessary. See Step 3 for explanations on type modifiers.
      int num1, num2, num3;
      Step3Learn the type modifiers: signed, unsigned, short and long. If you put one by itself, the compiler assumes you mean int. The short modifier makes an int 2 bytes while long makes it 4 bytes.
      Step4Initialize a variable by putting an equals sign after it and giving it a value. You can do this during the declaration or after it.

      int x = 14, y; // during declaration

      y = 34; // after declaration
      Step5Form an arithmetic expression using data types as follows:

      unsigned int seconds = 60, minutes = 60, hours = 24, total;

      total = hours * minutes * seconds;
      Step6Create a more complex data type by using char. An array is a data structure that can hold a row of elements of the same data type. An array of char functions as a string.

      char word[6] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘’};

      View Comment
    • Anonymous
    • April 29, 2014
    Reply

    What Should Be This Characters Field Of Expertise Be? The story takes place in a fictional world, but the technology is very modern like (with social structure being a mix of Victorian and Modern era).

    Anyways, the story follows an immortal bounty hunter (he’s a king from a long forgotten nation).

    Anyways, the character is generally quite absent minded. He’s a major blood knight, and is easily distracted from the main goal. He has a terrible sense of direction, and his partner has made numerous jokes about him; getting Alzheimer’s in his old age, or him getting shot in the head too many times. He’s also quite vain, for example; he wears an eye patch that he doesn’t need (he had to wear it when he lost an eye during a fight, but he has since grown a new one) because he thinks it makes him look more “badass”.

    Anyways, I thought it would be funny if I shocked readers by revealing that he was some sort of doctor or professor (his full name is Felix Larkin, what sounds better Doctor Larkin, or Professor Larkin?) in one of his past identities.
    No offense, but your answer makes absolutely no sense…

    View Comment
    1. Reply

      Lols, if you want a more slapstick comedy to him, you can always make him a pervert expert in girls “three” sizes or something like that haha! That would be comedy fun for guys *winks*

      If you want him to has at least ONE redeeming qualities about him in a more RL POV, you could make his expertise be something rather noble or respectable, like a good detective investigator (too cliched these days?) Or someone who is good at telling who a person really is by looking at one quality of a person’s body, like, ie, looking at one’s fingernails, hairstyle, or feet, or something! Just something eccentrically weirdly random! ?

      That would go well with his aloof comedious hilarious type of character!

      ?

      View Comment
    • Eclstate
    • May 11, 2014
    Reply

    How Do I Remove The First Character From A Field In Microsoft Access?

    View Comment
    1. Reply

      Use the Right function, providing that the field contains a fixed number of characters..

      You would need to create a query (MakeTableQuery) and insert a column to the right of the currrent column, Call this new column Temp:

      Then you would enter:

      Temp: Right([column1],7)

      If you do not have a fixed width field then you could run this query a number of times appending a new table until you have extracted all the new data

      View Comment
    • BABU
    • May 14, 2014
    Reply

    How To Format Timestamp In Oracle 10g? When i entering time in timestamp field of oracle 10g table through vb6.0 the time part of timestamp is taking correctly
    but the date part of the timestamp is always taking 30-dec-99
    how to make timestamp field to accept current date or sysdate
    thank you sir yuntaa_d
    sir but my table as both fields date and timestamp
    and i have to insert 60 records after every minute
    i had done as u said but when inserting date in date field it taking properly but timestamp againg taking 30-dec-99 as date part and time part as im inserting

    View Comment
    1. Reply

      Hi –

      It all depends on how you send the date to Oracle from VB.

      If you want to use the sysdate, and you always want to use the sysdate as the timestamp when inserting a record, then it is best to make the column in your Oracle table have a DEFAULT value of sysdate and not pass the date to Oracle when inserting the record. By default, if no value is passed to the date field, then on insert it’ll grab the sysdate by default and you don’t have to worry about it.

      As an example, say you have table TEST with 3 columns:

      SQL> create table test (x number, y timestamp default sysdate, z varchar2(12));
      Table created.

      SQL> insert into test (x,z) values (1,’hello’);
      1 row created.

      SQL> commit;
      Commit complete.

      SQL> select * from test;

      X Y Z
      ———- ——————————————— ————
      1 12-MAR-08 09.09.18.000000 PM hello

      Or you can explicitly enter sysdate as a value:

      SQL> insert into test (x,y,z) values (1,sysdate,’hello again’);

      1 row created.

      SQL> commit;

      Commit complete.

      SQL> select * from test;

      X Y Z
      ———- ———————————————— ————
      1 12-MAR-08 09.09.18.000000 PM hello
      1 12-MAR-08 09.12.13.000000 PM hello again

      View Comment
    • MetalHeadm/
    • May 16, 2014
    Reply

    What Does “Data Types” Mean? C++ meaning please:)

    View Comment
    1. Reply

      ” A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer, floating point unit number, character, string, and pointer. Usually, a limited number of such data types come built into a language. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored. ”

      Buddy you’re losing a lot of points by asking all these questions and I’m just going on google.

      View Comment
    • Kujo57us
    • May 28, 2014
    Reply

    What Is Wrong With This Timestamp Trigger? Oracle on unix via telnet

    CREATE OR REPLACE TRIGGER Emp_Timestamp_bc
    BEFORE Insert OR Update ON emp
    REFERENCING New AS New_Row
    FOR EACH ROW
    BEGIN
    :New_Row.Last_Update_User := USER;
    :New_Row.Last_Update_Date := SYSDATE;
    END Emp_Timestamp;
    /
    When I add a row to the emp table:
    insert into emp values
    (10, ‘Adam’, 50000, ‘MIS’);
    I get this error:
    ERROR at line 1:
    ORA-00947: not enough values
    Please Help!

    View Comment
    1. Reply

      Nothing wrong with the trigger you made. What is causing your problem is the insert statement.

      Several things needs to be considered in an insert statment.
      1. You need to make sure all NOT NULL columns is included in your insert statement

      2. If your not specifying the columns in the insert statement, make sure that the values clause contain ALL the columns in the table and in the correct order.

      3. You can also specify the columns which the insert statement will populate. In your example, insert into emp(col1, col2, col3, col4) values (10, ‘Adam’, 50000, ‘MIS’); Only col1, col2, col3, coll4 will have values and the other columns will have a value of null.

      View Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: