US and Worldwide: +1 (866) 660-7555
Results 1 to 7 of 7

Thread: Converting UAT (Date)

  1. #1

    Default Converting UAT (Date)

    I am a newbie to PDI. I am quering a database and grabbing data that has a following timestamp format:

    TIMERECORDED
    1335429814

    I want to be able to take the value above and then add 5 minutes. I will query the DB every 5 minutes and take 5 minute samples of data.

    What is the best method to handle coverting the date in a step? Calculator?

    Thanks in advance.

  2. #2
    Join Date
    Nov 2008
    Posts
    511

    Default

    Well, I'm not exactly sure what you're driving at but dates and times can easily be manipulated with the Java Calendar.

    Code:
    var date_recorded;
    var date_plus_5min;
    
    /*
     * Obtain an instance of the default Java Calendar.
     */
    cal = java.util.Calendar.getInstance();
    
    /*
     * Set the calendar to the recorded time.
     */
    cal.setTimeInMillis(TIMERECORDED * 1000);
    date_recorded = cal.getTime();
    
    /*
     * Add 5 minutes.
     */
    cal.add(java.util.Calendar.MINUTE, 5);
    date_plus_5min = cal.getTime();
    The preview of the result will look something like this:

    timerecorded.jpg
    pdi-ce-4.4.0-stable
    MySQL 5.5
    Windows 7 (32 bit)

  3. #3

    Red face

    Sorry my post was confusing. So this is EXACTLY what I wanted to accomplish. I wanted to convert the time and I will play with your sample. Thanks for the response.

  4. #4
    Join Date
    Nov 2008
    Posts
    511

    Default

    It wasn't so much confusion as it was skepticism. The TIMERECORDED value of 1335429814 represents the number of seconds since Midnight, January 1, 1970 (the unix epoch). Thus, adding 5 minutes could be as simple as adding 300 (seconds) to that value.

    Personally, I prefer the Java Calendar method to do my date/time manipulations because it handles things like Leap Years, Time Zones, and Locales.
    pdi-ce-4.4.0-stable
    MySQL 5.5
    Windows 7 (32 bit)

  5. #5
    Join Date
    Apr 2008
    Posts
    1,784

    Default

    It can also be accomplished in the Calculator step.
    I generally recommend people stay away from the Modified JavaScript Values step whenever possible.

  6. #6
    Join Date
    Nov 2008
    Posts
    511

    Default

    gutlez is right! I didn't know the Calculator step would do that.

    time_recorded_2.jpg
    time_calculator.jpg
    pdi-ce-4.4.0-stable
    MySQL 5.5
    Windows 7 (32 bit)

  7. #7

    Default

    Darrell -

    I used the calculator per your example. This is the way to go. Thanks for taking the time to upload the screenshot. Very helpful!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •