Friday, December 5, 2008

First and Last Day of Month

Add 2 prompts

First Prompt
Heading Type = RTF Long
Type = Character
Heading Text = Enter year (4 digit)
Format = Number Only
Length = 4
Unique Prompt Name = Bind1
Edit Type = No value

Second Prompt
Heading Type = RTF Long
Type = Character
Heading Text = Enter month (2 digit)
Format = Number Only
Length = 2
Unique Prompt Name = Bind2
Edit Type = No value

For all of the expressions you will need the settings

Type = Character
Length = 10

For the last day of the month
To use as a field enter in the text
  • TO_CHAR(LAST_DAY(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD')),'YYYY-MM-DD')
To use in criteria
  • TO_DATE(LAST_DAY(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD')),'YYYY-MM-DD')

For the first day of the month
To use as a field enter
  • TO_CHAR(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD')
To use in criteria
  • TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD')
First day of next month
To use a field enter
  • TO_CHAR(ADD_MONTHS(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD'),1))
To use in criteria
  • ADD_MONTHS(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD'),1)

Finally, last day of next month
To use a field enter
  • TO_CHAR(LAST_DAY(ADD_MONTHS(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD'),1)),'YYYY-MM-DD')

To use in criteria
  • LAST_DAY(ADD_MONTHS(TO_DATE(:1 || '-' || :2 || '-01','YYYY-MM-DD'),1))
With the ADD_MONTHS function, you can also use negative numbers to go to previous months.

As always, hope it helps.