PDA

View Full Version : string to date



kettle_anonymous
02-10-2006, 01:13 AM
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

MattCasters
04-12-2006, 04:16 AM
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

kedar mehta
01-25-2008, 06:10 AM
How can I compare Two dates?

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

For Kettle 2.5..

kedar mehta
01-25-2008, 11:54 AM
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");
}

kedar mehta
01-28-2008, 05:49 AM
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...


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,";
}

MattCasters
01-28-2008, 09:19 AM
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

kedar mehta
01-28-2008, 01:23 PM
Thanx matt..

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

n,Sorry for the bad formatting...!:D