Firebird 2.1 TIMESTAMP arithmetic and civil intervals
-
22-09-2019 - |
문제
My understanding is that, in keeping with Interbase v6, Firebird 2.5 does not support the SQL-92 INTERVAL
keyword. At least, so suggests this reference and my repeated SQLCODE -104 errors trying to get INTERVAL
s to work under Firebird's isql(1).
How, then, do I account for the irregularities in our civil reckoning of time -- months aren't uniformly long, nor are days with savings time and leap adjustments, not to mention the year of confusion, etc. -- when performing TIMESTAMP
arithmetic under Firebird 2.1?
How can I easily determine "one month earlier" or "one week later" than a given TIMESTAMP
? How about "one day later" or "two hours before"?
해결책
You may use the DateAdd() and DateDiff() built-in functions.
Alternatively you may also use classic date arithmetic.
다른 팁
If this isn't implemented in Firebird, maybe you could do it through the technology calling your sql server, and get the resulting timestamp ? I know it can be quite easily done in Java or .Net
You can also use the functions of the external UDF fbudf.dll
There is a nice external UDF named rFunc: http://rfunc.sourceforge.net/, it has nice Date functions like DaysBetween and IncDate(d, i1, i2, i3) and many more
- Subtract one day from timestamp date in a loop until month has changed.
- Subtract one day from timestamp date in a loop until day has changed to SUNDAY.