Home » RDBMS Server » Server Administration » Help : Date calculation
Help : Date calculation [message #370593] Tue, 04 January 2000 04:35 Go to next message
Siby Thomas
Messages: 2
Registered: December 1999
Junior Member
How to write a function, to calculate maturity date from the following.
The parameters are - opening date , current date, number of periods (number), unit (like year, month,Quarter,day).
Does anyone know if such a script already exists? Or does anybody have any tips about the use of existing date functions.

Thanks
Re: Help : Date calculation [message #370601 is a reply to message #370593] Wed, 05 January 2000 06:16 Go to previous messageGo to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
Siby,
Don't know of existing function, but it seems to be some fairly easy calculations -
to add/subtract days:
new_date := your_date + n;
new_date := your_date - n;
where n is the number of days to add/subtract
to add/subtract months:
new_date := add_months(your_date,n);
new_date := add_months(your_date,-n);
where n is the number of months to add/subtract
to add/subtract years, use add_months with (n * 12)
quarters depend on your definition,
either use add_months with (n * 3), if your definition of a quarter is 90 days,
or days with (n * 90), if you define a quarter as three months
If you use a 'house' definition of a year (I've seen both 360 and 364 day 'years') you can handle them like quarters ((n * 360) for example).
Hope this helps,
Paul
Re: Help : Date calculation - correction [message #370602 is a reply to message #370601] Wed, 05 January 2000 06:28 Go to previous messageGo to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
Siby,
Oops, slight error, reverse the notes on adding quarters:
n*90 to add 90 days, add_months(date,(n*3) to add 3 months. Also (should be obvious), if you define a month as 30 days use n*30 with the days logic, rather than the add_months() function.
Paul
Thanks: Date calculation [message #370634 is a reply to message #370602] Wed, 12 January 2000 04:55 Go to previous message
Siby
Messages: 1
Registered: January 2000
Junior Member
Thanks for your reply.
Previous Topic: Simultaneous select and update while row-locking?
Next Topic: Re: Looking for a good Sql reference book.
Goto Forum:
  


Current Time: Sat Oct 31 20:43:09 CDT 2020