Page 1 of 2

Timestamp conversion

Posted: Tue Jun 21, 2005 5:33 am
by srekant
Hi,

My input is Jan

Code: Select all

12 1995 12:00:00:000AM
and i want the output to be yyyymmdd.How can i achieve this.

Posted: Tue Jun 21, 2005 6:25 am
by ArndW
This is a string manipulation type operation, no real date mapping is needed. If your input date is in January as you stated and with your InString format as given you could do a In.InString[4,4]:'01':In.InString[1,2] to achieve your request result.

Posted: Tue Jun 21, 2005 6:42 am
by srekant
ArndW wrote:This is a string manipulation type operation, no real date mapping is needed. If your input date is in January as you stated and with your InString format as given you could do a In.InString[4,4]:'01':In.InString[1,2] to achieve your request result.
but my input date is not going to have month as jan every time

Posted: Tue Jun 21, 2005 6:44 am
by srekant
ArndW wrote:This is a string manipulation type operation, no real date mapping is needed. If your input date is in January as you stated and with your InString format as given you could do a In.InString[4,4]:'01':In.InString[1,2] to achieve your request result.
sorry the input is going to be like this

Code: Select all

Jan 12 1995 12:00:00:000AM
Aug 29 1995 12:00:00:000AM
and expecting output to be

19950112
19950707

Posted: Tue Jun 21, 2005 7:59 am
by ArndW
srekant,

that's nice, so your input format is different from your initial query. Now you need to use a date conversion algorithm instead of a string function. Have you looked at the date conversions that Px offers?

Posted: Wed Jun 22, 2005 5:09 am
by Prashantoncyber
Again, I feel it can be done as string manipulation with out using date

conversion like this,

if Field(Instring,1," ")=JAN

then In.InString[4,4]:'01':In.InString[1,2]

else In.InString[4,4]:'07':In.InString[1,2]

Hope not going against ArndW :)

Correct me if i am wrong?

Thanks

Prashant

Posted: Wed Jun 22, 2005 5:28 am
by ArndW
Prashant,

looking at your code, you would need to quote 'JAN' and if you only have dates in January and July then you will be set. But what happens with 'MAR'?

Posted: Wed Jun 22, 2005 6:12 am
by Prashantoncyber
Arndw,

That's true it will work only for JAN & AUG.
Seeing the sample data provided , i presumed so. :oops:

Thanks
Prashant

Posted: Wed Jun 22, 2005 10:47 am
by lshort
You could use the code below to determine the month number.
The rest should be a simple matter of concatenation and the StringToDate function.

Put the delimited Month list in the default value for a Stage Variable (svMM). Leave the derivation empty.

svMM(default) = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'


use this code to get the month number (ie. 01, 02...12) where Month is the string value from your input.

MM =((COUNT(svMM[1,Index(svMM,Month,1)],'|')+1)/100)[3,2]

Posted: Wed Jun 22, 2005 11:08 am
by lshort
mydate= 'May 12 1995 12:00:00.000 AM'

mydate[8,4]:((COUNT(X[1,Index(X,mydate[1,3],1)],'|')+1)/100)[3,2]:mydate[5,2]

Result = 19950512

Posted: Wed Jun 22, 2005 5:24 pm
by ray.wurlod
lshort wrote:You could use the code below to determine the month number.
The rest should be a simple matter of concatenation and the StringToDate function.

Put the delimited Month list in the default value for a Stage Variable (svMM). Leave the derivation empty.

svMM(default) = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'


use this code to get the month number (ie. 01, 02...12) where Month is the string value from your input.

MM =((COUNT(svMM[1,Index(svMM,Month,1)],'|')+1)/100)[3,2]
Lance,
Check out the lookup_int16_from_string operator in the Modify stage :idea:
Page 27-9 of Parallel Job Developer's Guide for v7.x

Posted: Wed Jun 22, 2005 10:00 pm
by info_ds
hi lance,

mydate= 'May 12 1995 12:00:00.000 AM'

DateToString(StringToDate(mydate[1,11],"%mmm %dd %yyyy"),"%yyyy%mm%dd")


can we implement this way?

Posted: Wed Jun 22, 2005 11:33 pm
by ray.wurlod
How about you try it and let US know? Lance is probably asleep as I post.

Posted: Wed Jun 22, 2005 11:45 pm
by info_ds
hi ray,

i tried and got the result --> 19950512

any suggestions?

yeah i also tried out and is working fine thanks guys.

Posted: Wed Jun 22, 2005 11:48 pm
by srekant
info_ds wrote:hi ray,

i tried and got the result --> 19950512

any suggestions?