how can i have previous month-end date(sept) in this month

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
BIuser
Premium Member
Premium Member
Posts: 238
Joined: Thu Feb 02, 2006 4:03 am
Location: South Africa

how can i have previous month-end date(sept) in this month

Post by BIuser »

Hi all

I want my job to have the previous month-end(September) date in this month(october).

what function or code can i use
-------------------------
https://www.ssa.co.za
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Re: how can i have previous month-end date(sept) in this mo

Post by sachin1 »

search for forum you will get answer
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Take today's date, substitute the day portion for the first day of the month, internalize the date, subtract one day, externalize the date:

Code: Select all

LastDayOfPreviousMonth = OCONV(ICONV((FIELD(OCONV(@DATE, "D-YMD[4,2,2]"), "-", 1,2):"-01", "D-YMD[4,2,2]") - 1, "D-YMD[4,2,2]")
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Are you looking for a specific kind of code? Because this requirement is posted for the 3rd time by same poster.

Answerd here: viewtopic.php?t=113535 and here : viewtopic.php?p=254377
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Obviously didn't like the answer and intends to keep posting the question until the preferred answer is posted.
:roll:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
baglasumit21
Participant
Posts: 132
Joined: Wed Mar 01, 2006 11:12 pm
Location: Pune

Re: how can i have previous month-end date(sept) in this mo

Post by baglasumit21 »

BIuser wrote:Hi all

I want my job to have the previous month-end(September) date in this month(october).

what function or code can i use
Try using a transfor to do it. We are currently using it to find the month-begin using a transform which takes 2 arguments, first is date and second is number of days to be substracted. For ex if i supply the parameter as 17-Oct-2007 and 30 days(1 month) then it will give me date as 1-sep-2007. In your case you can get the last day. Copy the below code in a txt file and import it using datastage manager. You will get a transform as DIFFMONTHFIRST. You can use it in the transformer stage of your job.

BEGIN HEADER
CharacterSet "CP1252"
ExportingTool "Ascential DataStage Export"
ToolVersion "4"
ServerName "10.1.1.211"
ToolInstanceID "SWIMJOBS"
MDISVersion "1.0"
Date "2004-10-18"
Time "12.11.05"
ServerVersion "7.5"
END HEADER
BEGIN DSTRANSFORMS
BEGIN DSRECORD
Identifier "DIFFMONTHFIRST"
DateModified "2004-09-19"
TimeModified "10.50.52"
OLEType "CTransform"
Readonly "0"
Category ""
ShortDesc "Substracts 6 Months From a Date"
Description =+=+=+=
This transform takes two parameters. first is a date in internal format and second is a no. of days to be substracted. It substracts the days from the date and gives the last day of that month as a result.

For Eg.
DIFFMONTHFIRST(13386,180)
gives 01-Feb-2007 which is last day of the date(28-Feb-2007) derived from 13886 (i.e. 24-Aug-2007) - 180 days

=+=+=+=
InputType ""
OutputType ""
NeedsDeffun ""
FunctionName "ConvertMonth"
ArgCount ""
CatalogName ""
ArgList ""
SourcePath ""
Version "2"
Expression "ConvertMonth((Oconv((%Arg1% - %Arg2%), 'D-YM')), "L")"
Arguments "CNameType"
BEGIN DSSUBRECORD
Name "Arg1"
Type ""
END DSSUBRECORD
BEGIN DSSUBRECORD
Name "Arg2"
Type ""
END DSSUBRECORD
END DSRECORD
END DSTRANSFORMS
SMB
Post Reply