Difference between two dates

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
imfarhan
Participant
Posts: 53
Joined: Tue Jul 24, 2012 9:34 am

Difference between two dates

Post by imfarhan »

I tried to use the following code but it does not like that.
the format of my fields(Admission_DTTM) is YYYY-MM-DD

Code: Select all

ABS(ICONV(IP_Spell_Epi_HRG_Src.ADMISSION_DTTM,'D4DMY')-ICONV(IP_Spell_Epi_HRG_Src.DISCHARGE_DTTM,'D4DMY'))
Appreciate your help
Farhan Syed
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I would use the format 'D4-YMD' for the Iconv() and Oconv() functions. If that doesn't work then please tell us how "...does not like that..."
imfarhan
Participant
Posts: 53
Joined: Tue Jul 24, 2012 9:34 am

Post by imfarhan »

Sorry I should have mentioned befoere my values is date+timestamp like :
2008-07-06 06:29:00.0

I think I need to conver into Date then time , in the following example I have used only one date , I assue if this work I can easily calculate difference by using minus - .

I don't know how ICONV function works?,

The following condition I have used in Stage Variable in Transformer


ICONV((TimestampToDate(IP_Spell_Epi_HRG_Src.ADMISSION_DTTM),'D4-YMD')
Many thanks
Farhan
Farhan Syed
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

FYI - Un-hijacked the original post.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

DataStage server doesn't have a date or a timestamp data type. If you do an Iconv() from a date using the correct mask ('D4-YMD' in this case) the result is an integer (the number of days since 31 DEC 1967). If you do an Iconv() from the time portion of the string using the mask 'HH:MM:SS' then you will received an integer number with the number of seconds since midnight.

Do you need the time component or do you just wish to use the date portion?
imfarhan
Participant
Posts: 53
Joined: Tue Jul 24, 2012 9:34 am

Post by imfarhan »

Thanks for your swift response.

I think I will calculate the difference on Date only Not timestamp.
So do I have to convert into Date first as currently the type in the db2 is TIMESTAMP and the difference values of (Admission DT) and (Discharge DT) will be in the field "Length_OF_Stay" field whose type will be VARCHAR(20)

Many thanks
Farhan
Farhan Syed
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

The values in the column in DataStage are going to be strings, so a substring will be sufficient, i.e.

Code: Select all

ICONV(IP_Spell_Epi_HRG_Src.ADMISSION_DTTM[1,10],'D4-YMD')
imfarhan
Participant
Posts: 53
Joined: Tue Jul 24, 2012 9:34 am

Post by imfarhan »

Stage Variable svLOS: ICONV(IP_Spell_Epi_HRG_Src.ADMISSION_DTTM[1,10],'D4-YMD')
Variable 'ICONV' not defined
Farhan Syed
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Is this a SERVER job or a PARALLEL job?
imfarhan
Participant
Posts: 53
Joined: Tue Jul 24, 2012 9:34 am

Post by imfarhan »

PARALLEL JOB
Farhan Syed
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

<sigh> There is no iconv in parallel jobs. This is posted in the Server section. The solution is very different in parallel jobs.

The timestamp data read from db2 into timestamp in the job is a "real" timestamp.

The derivation you want is "daysSinceFromdate(TimeStampToDate(In.Timestamp1),TimeStampToDate(In.Timestamp2))".
imfarhan
Participant
Posts: 53
Joined: Tue Jul 24, 2012 9:34 am

Post by imfarhan »

Oops! My apologies , I just search on the forum and found Date Difference and replied. I will be careful next time.
Sorry to confuse you and thanks for your help its works

Kind regards
Farhan
Farhan Syed
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Moved to the correct forum.

This is your thread now, so if it is working to your satisfaction please mark the thread as Resolved using the button at the top of the page.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply