If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Checking dates for month-end validation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-31-06, 06:40
exterminator exterminator is offline
Registered User
 
Join Date: Jan 2006
Posts: 38
Checking dates for month-end validation

Hi,

I have the following function:
Code:
CREATE FUNCTION isMonthEnd(inputDate DATE) RETURNING INT
	DEFINE month_end_date DATE;
	DEFINE return_val INT;
	LET month_end_date = inputDate + 1 UNITS MONTH - DAY(inputDate) UNITS DAY;
	IF (DATE(inputDate) == DATE(month_end_date)) THEN
		LET return_val=1;
	ELSE
		LET return_val=0;
	END IF;
	RETURN return_val;
END FUNCTION;
It doesn't seem to be working... I mean - it always returns 0. In case, when the date is month-end already - it fails - saying the computation is out of range because adding a month makes it invalid if it is 31st day and the next month does not have 31 days.. Can anyone help me fix this?

Apart from that, is there any easier way to get the month-end dates between given date range (start date to end date - both inclusive)? That would be great.

Thank you in advance!
Reply With Quote
  #2 (permalink)  
Old 07-31-06, 08:24
exterminator exterminator is offline
Registered User
 
Join Date: Jan 2006
Posts: 38
Okay, I fixed it by changing the logic:
Code:
DROP FUNCTION isMonthEnd;
CREATE FUNCTION isMonthEnd(inputDate DATE) RETURNING INT
	DEFINE return_val INT;
	DEFINE temp_date DATE;
	LET temp_date = inputDate + 1 UNITS DAY;
	IF (MONTH(temp_date) - MONTH (inputDate) > 0 ) THEN
		LET return_val=1;
	ELSE
		LET return_val=0;
	END IF;
	RETURN return_val;
END FUNCTION;
Regards.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On