Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date contained in current month or previous month?

Status
Not open for further replies.

smooveb

IS-IT--Management
Jul 20, 2001
161
US
This might be an easy question, but here goes! I need to determine if a date from my database CreateDate (dd/mm/yyyy format), falls within the current month or a previous month. I see a formula parameter titled LastdayofMonth, but I have too much trouble defining formulas to manipulate this properly. Any help would be appreciated!
B
 
Hi
u havent specified if your database is oracle or some other rdbms.
anyway if u r sure that the date frm your database is gonna be either of this month or the previous then u can do this
extract <mm> from sysdate (this might be sysdate() or current_date if u r using redbrick instead of oracle for instance)
then
<<<
if
<mm> - <mm of ur database date> = 1
>>>
then ur date belongs to last month
<<<
else
if
<mm> - <mm of ur database date> = 0
>>>
then ur date is of the current month.
LastaDayOfMonth function in BO returns the last date of the month for the date u provide as argument to this function.
There are easier ways of doing this in BO but i guess u shud familiarise urself with the date functions provided in BO. trust me it wud make matters easier.

You can try my approach using free hands sql in case u don wanna use the funcs provided by BO.

Regds
 
Thanks! Think I've got it.

When I first read your message, I was like - great, wonder how to extract mm from current date? That would've been a definite mystery to me. What I ended up doing was getting the last day of the previous month through a formula:

=lastdayofmonth(currentdate()-30)

Now I can do a comparison between it and the date I'm using. Perhaps I should learn more about this extraction you speak of...

Anyway, thanks again!
B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top