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

Thread: Date format

  1. #1

    Default Date format

    I want to use a str2date function in a Javascript like:

    str2date("31/12/2199 23:59:59","dd/MM/yyyy HH:mm:ss")

    but Alert(str2date("31/12/2199 23:59:59","dd/MM/yyyy HH:mm:ss")) shows me the date like 'Tue Dec 31 23:59:59 CET 2199'. I would have expected it like in the given format '31/12/2199 23:59:59'.

    Problem is that a comparison with another date is now always different.

    Any help appreciated.

    Thanks,
    Patrick

  2. #2
    Join Date
    Sep 2009
    Posts
    809

    Default

    Hi Patrick,

    str2date() creates a Date object for you, by parsing the given string in the given format. The alert converts this Date object to a string using a certain format, so it can display something intelligible. So that is expected behavior. You can convert a date object back to any string format using the date2str() functions.

    What's the issue at hand? If you want compare dates, you could call getTime() on date objects and compare those, for example. There's also more efficient ways to compare date objects, depending on what you'd like to do with this information. JS scripting is usually the slowest alternative

    If you'd post a minimal example of what you want to do, I could provide a sample.

    Cheers

    Slawo
    Do you want to know more? Check out Adventures with Open Source BI

  3. #3

    Default

    Hi Slawo,

    All we want to do is to check if a date that comes in is equal to the max dat 31/12/2199 23:59:59 as defined in the Dimension Lookup / Update step for a slowly changing dimension.

    Thanks,
    Patrick

  4. #4
    Join Date
    Sep 2009
    Posts
    809

    Default

    Hi Patrick,

    ... in this case the attached sample may give you some pointers. It is designed to avoid custom code, and still do the job. If you need a JS code sample, let us know.

    Cheers

    Slawo
    Attached Files Attached Files
    Do you want to know more? Check out Adventures with Open Source BI

  5. #5

    Default

    Hi Slawo,

    Thanks! We'll try to avoid custom code ;-)

    Patrick

  6. #6
    Join Date
    Nov 1999
    Posts
    9,688

    Default

    equal to the max dat 31/12/2199 23:59:59 as defined in the Dimension Lookup / Update step
    For that reason there is an option in the step to add a field labeled Last version (without stream field as source). With that you can simply compare & see if that field is 'Y'.

    HTH,
    Matt
    Matt Casters, Chief Data Integration
    Pentaho, Open Source Business Intelligence
    http://www.pentaho.org -- mcasters@pentaho.org

    Author of the book Pentaho Kettle Solutions by Wiley. Also available as e-Book and on the Kindle reading applications (iPhone, iPad, Android, Kindle devices, ...)

    Join us on IRC server Freenode.net, channel ##pentaho

  7. #7
    Join Date
    Dec 2012
    Posts
    3

    Default

    Hi,

    I am trying to convert string to date to in modified javascript. I cant use select values step due error handling steps that I am using. Dates are converted fine with following code when dates is with in range .if it is something like this 20111036 its been converted to Sat Nov 05 00:00:00 EDT 2011. is there anyway that I can get error if it is not in valid range like date should be 1 to 30.month should be in range 1 to 12.

    var DATE_FORMAT = "yyyyMMdd";
    var has_errors = 0;


    try{
    date_adddt = str2date(ADD_DATE,DATE_FORMAT);
    }
    catch(e){
    Alert("enetred into catch "+ADD_DATE);
    _step_.putError(getInputRowMeta(), row, 1, "Date format "+DATE_FORMAT+" expected", "ADD_DATE", "malformed date");
    has_errors = 1;
    }

    Thanks,
    Jetti.

  8. #8
    Join Date
    Dec 2012
    Posts
    3

    Default

    I did a workaround by comparing the date by converting back to string with original one.if not same just throw an error.

    var DATE_FORMAT = "yyyyMMdd";
    var has_errors = 0;


    try{
    date_adddt = str2date(ADD_DATE,DATE_FORMAT);
    if(ADD_DATE != date2str(date_adddt,DATE_FORMAT))
    throw e;
    }
    catch(e){
    _step_.putError(getInputRowMeta(), row, 1, "Date format "+DATE_FORMAT+" expected", "ADD_DATE", "malformed date");
    has_errors = 1;
    }


    if (has_errors == 0){
    trans_Status = CONTINUE_TRANSFORMATION;
    }
    else{
    trans_Status = SKIP_TRANSFORMATION;
    }

Posting Permissions

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