Substraction of month from the date

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
siva4joy
Premium Member
Premium Member
Posts: 34
Joined: Fri Apr 14, 2006 6:10 am
Location: London

Substraction of month from the date

Post by siva4joy »

hi,

could you please help me to find is there any function to substarct months from a given date.

i need to filter the records from the source data on a date column , if the 1st day of the previous month's date is friday then add 7 days to the particular date, filter those records which are not greater than the resultant date.

eg: 01-02-2008 is friday and i need to filter the records which are not greater than 08-02-2008. but my jobs are running in march.

Appreciate your help on this.
Thanks and Regards,
Sivasankar.z
+44-07807478984
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

This is one of the recent discussion about adding month, manipulate it.

viewtopic.php?t=118119&highlight=month

You can search for more different methodologies. But your post seems to be more focusing on adding 7 days of data to it??
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
savis
Premium Member
Premium Member
Posts: 27
Joined: Tue Apr 15, 2008 11:06 pm

Post by savis »

Hi,

Did you use this function:

DateFromDaysSince(7,StringToDate(<Date Field>,"%dd-%mm-%yyyy") )

Input output
01-01-2008 2008-01-08
11-02-2008 2008-02-18
01-03-2008 2008-03-08
21-02-2008 2008-02-28
01-02-2008 2008-02-08
05-01-2008 2008-01-12
03-02-2008 2008-02-10
05-02-2008 2008-02-12

Thanks,
Savis
siva4joy
Premium Member
Premium Member
Posts: 34
Joined: Fri Apr 14, 2006 6:10 am
Location: London

Post by siva4joy »

the logic should be ,whenever the first of the previous month falls on friday only i need to filter the records.
but how can i find the first of the previous month is friday?
for example if my job runs on today 21-04-08 then i need to check the first of the previous month 01-03-08 is friday or not .

appreciate your help to find out.
Thanks and Regards,
Sivasankar.z
+44-07807478984
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Do you have a time dimension table you can use in a lookup?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
siva4joy
Premium Member
Premium Member
Posts: 34
Joined: Fri Apr 14, 2006 6:10 am
Location: London

Post by siva4joy »

no we don't have any dimension tables.
the source data is coming from the flat file and we need to load in oracle.
Thanks and Regards,
Sivasankar.z
+44-07807478984
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Create a "time" table with daily granularity. You'll appreciate having it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

date +%Y" "%m | perl -ane ' use Time::Local; $wday = (localtime(timelocal(0,0,0,1,$F[1]-2,$F[0]-1900)))[6]; print $wday; '
Above code prints number ranges from 0 (for Sunday) through 6 (for Saturday). If it returns 5 then 1st day of previous month started on friday.
siva4joy
Premium Member
Premium Member
Posts: 34
Joined: Fri Apr 14, 2006 6:10 am
Location: London

Post by siva4joy »

I think a solution for this.
Take the year and month from the CurrentDate().
The date required is yyyy : (mm-1)only the value range between 02 and 12 : 01 . Use StringToDate function.
Then use the function WeekdayFromDate(1st of thePrevious Month Date) if it returns 5 then it is friday which i am looking for.

But it needs to test for my requirement.
Thanks and Regards,
Sivasankar.z
+44-07807478984
Post Reply