how to get end date of the month
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 103
- Joined: Wed Jul 06, 2005 12:29 am
how to get end date of the month
I have a scenario where in I need to take DSJobStartDate and find the end date of the previous month.I know how to get the end of the month but how do I go back to the previous month from DSJobStartDate.
Hi
Try this i got the logic from another post and modified the stage variables logic, but i am not sure.
Declare 3 stage variables like below.
SvRUN_DT = DSJobStartDate
svYear= YearFromDate(SvRUN_DT)
svMonth= MonthFromDate(SvRUN_DT)
Then in the output derivation for RUN_DT, put:
If MonthFromDate(RUN_DT) = 10 or MonthFromDate(RUN_DT) = 11 or MonthFromDate(RUN_DT) = 12 then
DateFromDaysSince(-1, StringToDate(svYear : "-" : svMonth : "-01") ) else DateFromDaysSince(-1, StringToDate(svYear : "-" : "0" : svMonth : "-01") )
Declare 3 stage variables like below.
SvRUN_DT = DSJobStartDate
svYear= YearFromDate(SvRUN_DT)
svMonth= MonthFromDate(SvRUN_DT)
Then in the output derivation for RUN_DT, put:
If MonthFromDate(RUN_DT) = 10 or MonthFromDate(RUN_DT) = 11 or MonthFromDate(RUN_DT) = 12 then
DateFromDaysSince(-1, StringToDate(svYear : "-" : svMonth : "-01") ) else DateFromDaysSince(-1, StringToDate(svYear : "-" : "0" : svMonth : "-01") )
If DSJobStartDate = 2008-10-15, then subtract the number days. In this case, 15.
In DB2 SQL, this would be as follows:
or
Seems like this should always give you the last day of the prior month, shouldn't it? I haven't done much date arithmetic in DS, we typically are pulling from a database and do it in SQL. Does DS have an easy way to subtract N number of days from a date and have a valid date?
Brad
In DB2 SQL, this would be as follows:
Code: Select all
select current date - day(current date) days .....
Code: Select all
2008-10-15 - 15 days = 2008-09-30
Brad
It is not that I am addicted to coffee, it's just that I need it to survive.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: