Saturday, May 5, 2018

Using MONTHS_BETWEEN in PLSQL Query

https://randomsrsolutions.blogspot.com/2018/05/using-monthsbetween-in-plsql-query.html

MONTHS_BETWEEN(date1, date2): Finds the number of months between date1 and date2. The result can be positive or negative. If date1 is later than date2, the result is positive; if date1 is earlier than date2, the result is negative . The non-integer part of the result represents a portion of the month.


select MONTHS_BETWEEN('14-AUG-2008','14-AUG-1947') TOT_MONTHS,
MONTHS_BETWEEN('14-AUG-2008','14-AUG-1947')/12 TOT_YEARS,
MONTHS_BETWEEN('14-AUG-2008','14-AUG-1947')*4 TOT_WEEKS,
MONTHS_BETWEEN('14-AUG-2008','14-AUG-1947') *30 TOT_DAYS,
MONTHS_BETWEEN('14-AUG-2008','14-AUG-1947')*30*24 TOT_HOURS
from Dual;

TOT_MONTHS    TOT_YEARS    TOT_WEEKS    TOT_DAYS   TOT_HOURS
         732                      61                    2928               21960             527040

No comments:

Post a Comment

XLA to GL Link

  https://plsqlquery.blogspot.com/2025/12/xla-to-gl-link.html SELECT             acr.cash_receipt_id,             acr.receipt_number,       ...