CurrentDate() Year extract

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
Yizi
Participant
Posts: 2
Joined: Wed Feb 03, 2016 3:21 am

CurrentDate() Year extract

Post by Yizi »

Hi all, this is my first post, sorry if it's a duplicate I did do a search beforehand... I'm pretty new to DS and I'm stuck trying to extract the year part from CurrentDate() function. Below is my SQLany help is appreciated.

Code: Select all

If (lkCopyTrans.CardExp <> 'xxxx' OR lkCopyTrans.CardExp <> '') Then 
StringToTimestamp(
(If AsInteger(lkCopyTrans.CardExp[1,2]) - ( CurrentDate()-1990) < 0 Then '19' Else '20')
 : lkCopyTrans.CardExp[1,2]  : '-' :
(If Len(lkCopyTrans.CardExp[3,2]) = 2 And AsInteger(lkCopyTrans.CardExp[3,2]) >=0 and lkCopyTrans.CardExp[3,2] <= 12 Then lkCopyTrans.CardExp[3,2] Else '12')
 : '-01 00:00:00'
, "%yyyy-%mm-%dd %hh:%nn:%ss") Else
StringToTimestamp('2025-12-01 00:00:00',"%yyyy-%mm-%dd %hh:%nn:%ss")
I would write it like this if it was PL-SQL: DateExtract('Year',current_date)-1990)
Apologies in advance if i have broken any rules...

[EDIT - Job type changed to Parallel - Andy]
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No worries about the rules. Yet. :)

So this is actually for a Parallel job and not a Server job type as posted?
-craig

"You can never have too many knives" -- Logan Nine Fingers
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

DataStage Parallel transformer has a few inbuiltfunctions to help with such conversions.

YearFromDate function will extract year from a Date. For current year ... YearFromDate(CurrentDate())
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

Post by skp »

Hi,

Datastage default CurrentDate() format is %yyyy-%mm-%dd

so use below logic to extract the current year from CurrentDate() function.

Left(CurrentDate(),4)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

skp wrote:Datastage default CurrentDate() format is %yyyy-%mm-%dd
This is not necessarily true. For starters, the return value is of type Date, which is a binary number. Secondly, the default format when converting to a string depends on the locale, and the default set using the Project Properties in the Administrator client.
The Left() function forces a data type conversion from date to string.
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