Hi All,
I have one requirement.
Requirement: Take the current date and check the date if day is >20 then take the month as current month Else take the previous month with day as 01 always.
Ex: 21-02-2014 .here day is greater then 20 output= 01-02-2014
02-03-2014 here day is less than 20 take the previous month date : 01-02-2014
Could you please help me the above?
Date Conversion?
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Use functions MonthDayFromDate(), MonthFromDate() and YearFromDate() to extract the components, do your math, then use DateFromComponents() function to re-assemble the date.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
MonthDayFromDate() would not be necessary, as the resulting day of the month is always day 1.
Make sure to test dates ranges including January 1st through 20th, to ensure it falls back to the previous year.
You may be able to avoid the "check the date if day is > 20" and similar "If Then Else" logic by doing the date math up front. Would this work?
Stage variable:
Derivation:
Make sure to test dates ranges including January 1st through 20th, to ensure it falls back to the previous year.
![Idea :idea:](./images/smilies/icon_idea.gif)
Stage variable:
Code: Select all
svTempDate = DateOffsetByDays(incoming_date, -20)
Code: Select all
DateFromComponents(YearFromDate(svTempDate), MonthFromDate(svTempDate), 1)
Choose a job you love, and you will never have to work a day in your life. - Confucius