Posted: Mon Jul 06, 2015 6:09 am Post subject: Date calculation using IINTERVAL
Newbie
Joined: 02 Jun 2011 Posts: 8
I am calculating time using INTERVAL like below
DECLARE dateStr1 CHARACTER '2015-07-30';
DECLARE MSGDATE1 TIMESTAMP;
SET MSGDATE1 = CAST(dateStr1 AS TIMESTAMP FORMAT 'yyyy-MM-dd');
SET Environment.Variables.Dates.CAQHEndDate1 = MSGDATE1 + CAST(11 AS INTERVAL MONTH);
in this case its working fine output is '2016-06-30'
But once i am changing the date to 31 like
DECLARE dateStr1 CHARACTER '2015-07-31';
still its giving '2016-06-30'.
Posted: Mon Jul 06, 2015 6:30 am Post subject: Re: Date calculation using IINTERVAL
Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
alokamit72 wrote:
But once i am changing the date to 31 like
DECLARE dateStr1 CHARACTER '2015-07-31';
still its giving '2016-06-30'.
What were you expecting? 2016-06-31?
If you were, stop and think of why that didn't happen. Hint - nothing to do with code and everything to do with the Gregorian calendar.
If you were expecting 2016-07-01, then that's not what you've coded. If you're not happy with the software's inbuilt handling of days 29 - 31 (imagine if your start date was 2015-03-30) then you need to code something else. _________________ Honesty is the best policy.
Insanity is the best defence.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum