Datediff function in Oracle
As I am working on Oracle database at my day job, I have found something that is by default on sqlserver but not in oracle. That is the datediff function that given the input of two dates and an identifier like day, month or year returns integer with the requested number.
So to cut the long story short, I have written my own datediff function for oracle use. You can request more return types in the comments, and I will be glad to add them. Here is the code:
As you can see, the type parameters are: MONTH for difference in months, DAY for difference in days and YEAR for difference in years respectively.
I hope oracle will see the light and include this function in any of the future releases.
UPDATE: As my friend LILkillaBEE has mentioned that he could be in a need of hour/minute/second difference, I have added that too, so, this should be the final implementation.
New parameters are HH for hour, MM for minute and SS for seconds difference.
Comments