Max Value in date column

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
jayantthakore
Participant
Posts: 42
Joined: Tue Jan 18, 2005 5:48 am

Max Value in date column

Post by jayantthakore »

Hii all,
I have a column which has date value [SAMPLE(1900-01-01)] in a character (10) field.I have to find the max date out of this column.Max function is not working. Can you help me on this

thanks
Jayant
shails
Participant
Posts: 27
Joined: Mon Jul 18, 2005 2:55 am

Post by shails »

Max function does not work on a date column. You can convert the char column to date and then use Juliandayfromdate function which gives a integer value of the date. Aply max function on this integer column. If you want date again you can use datefromjulianday function.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What stage type are you using to apply Max() ? Given that the field is string[10], you should be able to use an Aggregator stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
htrisakti3
Charter Member
Charter Member
Posts: 36
Joined: Thu Jun 10, 2004 11:22 pm

Post by htrisakti3 »

Have you tried:

iDate = IConv(fieldName, "D-YMD")

iDate is now integer & you can easily Max(iDate),

But you have to: OConv(iDate, "D-YMD")
to display this back as proper date
cmmurari
Participant
Posts: 34
Joined: Sun Jan 02, 2005 9:55 am
Location: Singapore

Post by cmmurari »

you should be able to use an Aggregator stage.

htrisakti3 , The basic rule is not all Basic functions work in parallel jobs
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

hi jayantthakore,
i agree with Shails. In DataStage to find max value in a column, you need to use Aggregator Stage. Output of an aggregator stage is a decimal value.

To find max value of column SAMPL(1900-01-01) You need to conver it to date first and then convert it to julian date then use this julian data as your column for calculation.

With string dta type you will not get output properly.
Happy DataStaging
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

hi,
Other way is to sort the data based on the group, and retain last/first using remove duplicate to get the max of date.

regard
kumar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

htrisakti3 wrote:Have you tried:

iDate = IConv(fieldName, "D-YMD")

iDate is now integer & you can easily Max(iDate),

But you have to: OConv(iDate, "D-YMD")
to display this back as proper date
Iconv and Oconv are not natively available in parallel jobs.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
dxp
Charter Member
Charter Member
Posts: 48
Joined: Sat Oct 01, 2005 10:23 am

Post by dxp »

hi i got a different solution for this problem.
using modify stage i converted
date to----------> days_since_from_date(date), which is of date format-----to----->int32.----------->then in Aggregator..max(date in int32 format)------------>in modify stage...int32 to date...date_from_days_since(date in int32 format).
it works.

any comments?
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post by clshore »

I think the date string format you have is almost suitable for direct selection:

[SAMPLE(1900-01-01)]

If you simply remove the dashes from the string, and convert the result to a number, then max() works.

ie, '1900-01-01' ==> 19000101

You can lexically remove the dashes, or do substrings and rembine, or whatever you wish to convert. It's got to be computationally easier than multiple up/down date conversions.

Carter
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Why can't you just get the max of the string[10] field? You can do it in SQL, so you should be able to do it in an Aggregator stage. Dates in ISO 8601 format - which this is - sort properly, at least in the year range 1AD through 9999AD.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply