Hitachi Vantara Pentaho Community Forums
Results 1 to 7 of 7

Thread: string to date

  1. #1
    Join Date
    Sep 2005
    Posts
    1,403

    Default string to date

    Hi, sorry to bother you again with a newbie question
    how can i convert a string to a date?
    my query returns this string:


    2004/01/11 00:00:00.000



    Spoon won't convert this to a date



    I am stuck



    Greetings, Remco

  2. #2
    Join Date
    Nov 1999
    Posts
    9,729

    Default RE: string to date

    Remco,

    use a small piece of javascript with the str2dat function:
    In your case, that would be

    Field.str2dat("yyyy/MM/dd HH:mm:ss.SSS");

    However, that is also the default conversion mask for Kettle, so you can just change the metadata using a Select Values step and you'll be fine.

    All the best,

    Matt

  3. #3
    Join Date
    Jun 2007
    Posts
    138

    Default Modified java script

    How can I compare Two dates?

    One is, in the format, YYYY/MM/DD
    Another is kettle system date.

    For Kettle 2.5..
    Last edited by kedar mehta; 01-25-2008 at 11:37 AM.
    Regards,
    kedar.mehta@tcs.com ,
    Tata consultancies Ltd

  4. #4
    Join Date
    Jun 2007
    Posts
    138

    Default date parsig

    I found it,

    if (Date.parse(sysDateJava) > Date.parse(datInital)) {
    Alert(" left side is bigger then right side");
    }

    else{
    Alert(" left side is smaller then right side");
    }
    Regards,
    kedar.mehta@tcs.com ,
    Tata consultancies Ltd

  5. #5
    Join Date
    Jun 2007
    Posts
    138

    Default date comparision problem

    sysDate is:Kettle system date
    Its coming as,
    28th Jan 2008 ..some thing like dat.

    datIntial is:2007/01/01

    I want to compare both.How can I?
    See me code..

    It always give me
    datInitial is bigger then sysDate !!1

    See the code...
    Code:
    var sysDateJava=SYS_DATE.getDate(); var datInital =INITIAL_DATE.Clone().str2dat("yyyy/MM/dd"); var flagdatInital_Format=isRegExp(str_AMOUNT_OF_DISCOUNT,VALIDATOR_GRAMMAR_FECHA_INITIAL_KEDAR); var flagdatInital_Big=1; Alert("sysDateJava"); Alert(sysDateJava); Alert("datInital") Alert(datInital); if(flagdatInital_Format==-1){ //invalid format-->String. Not null
    error_field="FECHA DE INICIO,"; errr_flags="LA FECHA TIENE FORMATO INCORRECTO,"; } else {
    } if (Date.parse(sysDateJava) > Date.parse(datInital)) { //La fecha de inicio no puede ser menor que la fecha actual Alert(" left side is bigger then right side"); flagdatInital_Big=1; } else { Alert(" Right side is bigger then left side"); flagdatInital_Big=-1; error_field="FECHA DE INICIO,"; errr_flags="LA FECHA NO PUEDE SER MAYOR QUE LA FECHA ACTUAL,";
    }
    Last edited by MattCasters; 01-28-2008 at 09:18 AM.
    Regards,
    kedar.mehta@tcs.com ,
    Tata consultancies Ltd

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

    Default

    Dates are not primitive JS types. As such, comparing them using > is not allowed. (you are comparing Object address locations, not object values)

    You can either use the method "Date.compareTo(OtherDate)" or convert the dates to Integer: d1.getInteger() > d2.getInteger()

    Matt

  7. #7
    Join Date
    Jun 2007
    Posts
    138

    Default parse

    Thanx matt..

    Even parse date is working.It just expcets,string as input.I was giving Date instead...

    n,Sorry for the bad formatting...!
    Regards,
    kedar.mehta@tcs.com ,
    Tata consultancies Ltd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.