Subract the date with 365 days

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
mdtauseefhussain
Participant
Posts: 38
Joined: Mon Feb 27, 2006 10:34 pm
Location: Chennai
Contact:

Subract the date with 365 days

Post by mdtauseefhussain »

HI! All

I have a date column UDT_DATE ,iam using this date to calculate the flag
My condition
If UDT_DATE>=(last 12 months ) Then 'Y' ELse 'N' .So i used this way

If UDT_DATE>= Sysdate-365 Then 'Y' ELse 'N' .I bring the Sysdate form the source level .The problem when i tried to subract the sysdate with 365 i was not able to do so can any one help me in this


Thanks in advance
Mohammed Tausif Hussain Sheikh
Cognizant technologies,Perungudi
Chennai
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You can use the DataStage variable @DATE to get the current date in internal numeric form. I don't know what format either your UDT_DATE or "sysdate" is in, so can't comment on why it isn't working. Is the "sysdate" a job parameter?
mdtauseefhussain
Participant
Posts: 38
Joined: Mon Feb 27, 2006 10:34 pm
Location: Chennai
Contact:

Post by mdtauseefhussain »

Both te formats are in YYYY-MM-DD HI24:MI:SS ,iam not passing Sysdate as a parameter ,instead iam using

SELECT TO_CHAR(UDT_DATE, 'YYYY-MM-DD HH24:MI:SS'),
TO_CHAR(DATETIME_ADDED, 'YYYY-MM-DD HH24:MI:SS'),
to_char(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS LAST_UDT
FROM edw_product_d
and pulling the sysdate column in transformer an then iam trying to subract with 365 ,i tried using @DATE system variable its giving date in this format eg:14023 ,i didnt understand this date do i need to use any othe statements along with @DATE ,can we subract 365-@DATE
Mohammed Tausif Hussain Sheikh
Cognizant technologies,Perungudi
Chennai
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

To subtract 365 days from the current date use:

@Date - 365

@DATE returns date in internal format. You need to use OConv to change it in your format.

E.g OConv(@Date,"Date Format")
mdtauseefhussain
Participant
Posts: 38
Joined: Mon Feb 27, 2006 10:34 pm
Location: Chennai
Contact:

Post by mdtauseefhussain »

Thanks for your help
Mohammed Tausif Hussain Sheikh
Cognizant technologies,Perungudi
Chennai
rwierdsm
Premium Member
Premium Member
Posts: 209
Joined: Fri Jan 09, 2004 1:14 pm
Location: Toronto, Canada
Contact:

Post by rwierdsm »

mdtauseefhussain wrote: SELECT TO_CHAR(UDT_DATE, 'YYYY-MM-DD HH24:MI:SS'),
TO_CHAR(DATETIME_ADDED, 'YYYY-MM-DD HH24:MI:SS'),
to_char(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS LAST_UDT
FROM edw_product_d
Rather than do date manipulation in DS, (which I avoid at all costs!), do it in your SQL, i.e.

Code: Select all

SELECT TO_CHAR(UDT_DATE, 'YYYY-MM-DD HH24:MI:SS'),
TO_CHAR(DATETIME_ADDED, 'YYYY-MM-DD HH24:MI:SS'), 
to_char(SYSDATE -365, 'YYYY-MM-DD HH24:MI:SS')  AS LAST_UDT_MINUS_365 FROM edw_product_d
Using my example above, you would have to change the name of your input column.

Hope this helps,

Rob W
Rob Wierdsma
Toronto, Canada
bartonbishop.com
mdtauseefhussain
Participant
Posts: 38
Joined: Mon Feb 27, 2006 10:34 pm
Location: Chennai
Contact:

Post by mdtauseefhussain »

I did that before but i was getting null value in datastage
Mohammed Tausif Hussain Sheikh
Cognizant technologies,Perungudi
Chennai
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

My advice do it in the transformer. Your column values are timestamps. Just extract the date part, Iconv it and then subtract. Also if you do the manipulation in the transformer, that also makes your code flexible to be moved between different environments/databases.
Regards,
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply