Checking if date falls in a specified month in Oracle
procedure Charge(p_inputdate N VARCHAR2,//Date which accepts only MMYYYY format
inout_Cur OUT result_cur) IS
I need to validate the effective_date which is in date format (mm/dd/yyyy hh:mm:ss)
For example: The user enters 112013
as input and the effective date to check is 11/12/2013 09:13:22
Is it possible to find whether the effective date falls within the specified month?
can you please comment on this..
I tried below way:
V_INPUTDATE := to_char(TO_DATE(IN_INPUTDATE, 'MMYYYY','mmyyyy'));
v_effectiveDate := substr(V_INPUTDATE,1,2)+'/'+'01'+'/'+substr(V_INPUTDATE,3,4);
01 is nothing but month always start with 01(dd) Is this rightway ..??
If date happens to be a VARCHAR2
you need to first convert it to DATE:
effective_date DATE; -- Put this line in the declare section
effective_date := to_date('11/12/2013 09:13:22', 'MM/DD/YYYY HH24:MI:SS');
When you have the date, the rest is easy:
IF p_inputdate = to_char(effective_date, 'MMYYYY') THEN
-- Date is ok.
ELSE
-- Date is not ok.
END IF;
链接地址: http://www.djcxy.com/p/36952.html
上一篇: 在SQL中使用的日期之间的比较
下一篇: 检查日期是否在Oracle的指定月份中