How to calculate age in oracle
Hi,
T was trying do calculate age as on todays date in ORACLE but after a lot of brain storming i didn't get it.
Kindly tell me how to calculate age as in years month days.
For ex.. My DOB- 02-feb-1984 so my age should get as 27 Years 2 months 8 days
How to do it.
I tried this
select
TRUNC( months_between( sysdate, TO_DATE('02-02-1984','DD-MM-YYYY') )/12 ) Year,
TRUNC( mod(months_between( sysdate, TO_DATE('02-02-1984','DD-MM-YYYY') ),12) ) Month,
mod(months_between( sysdate, TO_DATE('02-02-1984','DD-MM-YYYY') ),12) /30 Days
from dual
but days are not calculating correctly...
RGds,
PC
sorry..i didn't chck your query..it is right but give wrong answer..
WITH got_months AS
SELECT TO_DATE('02-02-1984','DD-MM-YYYY')
, FLOOR (MONTHS_BETWEEN (SYSDATE, TO_DATE('02-02-1984','DD-MM-YYYY'))) AS months
FROM dual
SELECT TO_DATE('02-02-1984','DD-MM-YYYY')
, TO_CHAR (FLOOR (months / 12)) || ' years, ' ||
TO_CHAR (MOD (months, 12)) || ' months, ' ||
TO_CHAR ( CEIL ( SYSDATE
- ADD_MONTHS ( TO_DATE('02-02-1984','DD-MM-YYYY')
, months
) || ' days'
FROM got_months
o/p
TO_DATE('02-02-1984','DD-MM-YY TO_CHAR(FLOOR(MONTHS/12))||'YE
1 2/2/1984 27 years, 7 months, 9 days
1 day more..1 it sud be.. 2/2/1984 27 years, 7 months, 8 days
if i make correction with add_months like below..
WITH got_months AS
SELECT TO_DATE('02-02-1984','DD-MM-YYYY')
, FLOOR (MONTHS_BETWEEN (SYSDATE, TO_DATE('02-02-1984','DD-MM-YYYY'))) AS months
FROM dual
SELECT TO_DATE('02-02-1984','DD-MM-YYYY')
, TO_CHAR (FLOOR (months / 12)) || ' years, ' ||
TO_CHAR (MOD (months, 12)) || ' months, ' ||
TO_CHAR ( CEIL ( SYSDATE
- ADD_MONTHS ( TO_DATE('02-02-1984','DD-MM-YYYY')
, months
)-1
) || ' days'
FROM got_months
then o/p is..
TO_DATE('02-02-1984','DD-MM-YY TO_CHAR(FLOOR(MONTHS/12))||'YE
1 2/2/1984 27 years, 7 months, 8 days
correct but cdnt understand why sud -1?
Similar Messages
-
ABAP-HR MODULE(HOW TO CALCULATE AGE & YEARS OF SERVICE)
HI,
HOW TO CALCULATE AGE & YEARS OF SERVICE means for example
I AM USING PNPCE LDB.
(1) whose age is greater than 52.833 years with 7.833 years of service, with annual rate of pay $170,000 or more, or
(2) age plus employment service is 65 or more, with annual rate of pay of $ 170,000 or more.
Note that the $ 170,000 parameter would be a variable that could change annually when this report would be generated. In the past, age and service value were determined as of the run date. The determination date would also be a variable that would change when the report would be generated.
Thanks&Regards
Rahul.Hi Rahul,
This is the 2nd warning !!! Please... use the correct or most appropriate forum.
The ABAP Objects Forum should be used for: ABAP Object definition and implementation including encapsulation, interfaces and inheritance in ABAP Objects.
This thread will be moved from to .
You're asking this question in two thread, so the duplicated thread will be deleted.
Please have a look at [Forum Rules of Engagement|https://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement] before posting.
Also read this thread Welcome and Rules of Engagement.
Greetings,
Marcelo Ramos -
How to Calculate AGE by getting difference between two Date Fields
HI Gems
I need to calculate AGE from getting difference from two date fields. But when i am trying to wrte fromula as Current date - date1(some date field) then it is showing error.
How can i get values.
Thanks
ManuYou already asked this question:
How to calculate AGE from two different date fields -
How to calculate AGE from two different date fields
hi
I need to calculate AGE from two different date fields.
Can some help me how to do, when i try to do substraction formula it is showing error.
Thank You
ManuManu wrote:
Hi
Both fields are in date format only, i need to calculate no . of days between two different dates
Thanks
ManuThe reason for the question about the format of the column is because the simplest solution only works on DATE columns. Others have mentioned this here, but if you want the difference between two date fields, you can use this formula:
TIMESTAMPDIFF(SQL_TSI_DAY, date_column1, date_column2)
The above being said, you still didn't tell me what you did, or what error message you received. So again, if the above formula didn't work, what did you do? Where did you put the formula? What was the exact syntax you used? What was the error message you got?
Please don't make us work more than we need to. Answer all the questions in your next post. Thanks. -
How to calculate age in SQL?
I have a table with DATE as one of the column.
How do I calculate age?
Thanks in advance
-Shilpamichaels2 wrote:
TryWell it still leaves leap year question open. If person was born on February 29, how old is that person on February 28 of a non-leap year? Your code considers it imcomplete year:
SQL> var dob varchar2(20)
SQL> exec :dob := '19960229';
PL/SQL procedure successfully completed.
SQL> select trunc ( (to_number (to_char (to_date('20090228','yyyymmdd'), 'yyyymmdd'))
2 - to_number (to_char(to_date(:dob, 'yyyymmdd'),'yyyymmdd'))
3 )
4 / 10000)
5 as "Age of Child"
6 from dual
7 /
Age of Child
12SY. -
how do i calculate age based on date picker in another field on the same table/
Are you sure of that algorithm?
orclz> SELECT Round((SYSDATE-to_date('01-JAN-1989','dd-MON-yyyy'))/365) FROM DUAL;
ROUND((SYSDATE-TO_DATE('01-JAN-1989','DD-MON-YYYY'))/365)
25
orclz> SELECT Round((SYSDATE-to_date('01-DEC-1989','dd-MON-yyyy'))/365) FROM DUAL;
ROUND((SYSDATE-TO_DATE('01-DEC-1989','DD-MON-YYYY'))/365)
24
How about this:
orclz> select extract (year from sysdate) - extract( year from to_date('01-DEC-1989','dd-MON-yyyy')) from dual;
EXTRACT(YEARFROMSYSDATE)-EXTRACT(YEARFROMTO_DATE('01-DEC-1989','DD-MON-YYYY'))
24
orclz> select extract (year from sysdate) - extract( year from to_date('01-JAN-1989','dd-MON-yyyy')) from dual;
EXTRACT(YEARFROMSYSDATE)-EXTRACT(YEARFROMTO_DATE('01-JAN-1989','DD-MON-YYYY'))
24
orclz> -
How to calculate Age in BEx query
Hi,
I need to calculate age in years based on person's date of birth and the key date that user of the report will enter.
So, basically in my query I already have date of birth characteristic from 0PERSON InfoObject. I created ZAGE key figure and added it to the query that I would like to populate with person's age.
So I know I have to enter some code in CMOD for calculated key figure ZAGE to get calculated based on birthdate and key date that user enters. Can somebody help with the code?
thanksHi,
The variable should be in "Date" dimension. I have missed one important information in earlier mail.
The processing type of the variable (user entry date) should be of "Customer Exit' and dimension (in last tab) should be "Date".
By selecting this dimension, the variable input help screen also appears in calendar format to help user to select date instead of writing it in variable input.
No need to write any custom code for this variable. We are selecting the "Customer exit" processing type to get Date dimension. In Normal user entry variables we can't get date & time dimension.
"Ready for Input" should be selected so that user can enter date.
I hope you can solve your issue now.
Thanks for your feedback.
Regards,
Arun Thangaraj.
Edited by: Arun Thangaraj on Oct 8, 2008 8:48 AM -
How to calculate aging iin query desiner in bi7.0
Hi all,
can any help me how to write a formula in bex QUERY desiner bi7.0
acullay i have service order creation date in my cube ERDAT and
business requirements is calculate the aging
i want to minus the current date with creation date and i need the result in DAYS
i am new to BI .
Regards,
RajaWhy ask same question again ????
How to write a formula in BEX in bi7.0
Create a formula variable of replacement path on service order creation date say ZSCRE
Create a customer exit variable and populate sy-datum into it in the user exit of CMOD say ZSYDAT
or
There is one standard variable available as key date in BEX you can use that too.
Create a formula or CKF :
Age days = ZSYDAT - ZSCRE.
Hope this helps.
Edited by: Praveen G on Sep 15, 2008 5:14 AM -
How to Calculate %age value
Hi All,
i have a query
I have data like below
cy
data
CY 2008
4290421
CY 2009
4069379
CY 2010
3979492
CY 2011
3940169
and i want output like this
cy
data
CY 2008
4290421
% change
-5%
CY 2009
4069379
% change
-2%
CY 2010
3979492
% change
-1%
CY 2011
3940169
for percent change the formula is in excel for %age change of CY 2008 to CY 2009 = (CY 2009 / CY 2008 -1 )*100
how we can calculate in SAP BO INFOVIEW 3.1 and it will run automatically in future also for 2012,2013 so on
Please Advice..
Thanks in advance.
RanjeetHi Riaz,
Sorry for delay response
Please find the attachment
variable (formula) =([data]/Previous([data])-1)*100
the final result
if you want more information let me know
Thanks
Ranjeet -
How to calculate age for a business partner for segmentation purposes?
How do I calculate the age of a BP based on this person's maintained birthday on BP master data? I need to use this information to segment based on age groups, eg age 30-40, age 25 and below etc.
I did quite a bit of search on this forum but couldn't find anything. I know I've seen them somewhere before. Would appreciate any help and will reward points. Thanks!Hi Jo,
You can achieve this by using infosets.
Create Infoset using direct read of table BUT000.
In infoset select extras for additional field button and give following code for calcualting the difference between Birthdate and system date.
CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
i_date_from = but000-BIRTHDT
I_KEY_DAY_FROM =
i_date_to = sy-datum
I_KEY_DAY_TO =
I_FLG_SEPARATE = ' '
IMPORTING
e_days = test
E_MONTHS =
E_YEARS =
Create a datasource with Business partner GUID and assign it attributelist.
Choose the additional field for filter criteria.
Hope it solves your problem.
Reward points if it helps.
Regards,
Madhu -
How to calculate Age(more details)
Hi
I want to calculate the age but not only depending on substracting the years, i have to take into consederation the day and month and year
for example
taking into consederation that the date today is 08/08/1999
someone born on 1/1/1970
he is 29
someone born on 18/09/1963
he is 35
someone born on 12/12/1976
he is 22
how can we calculate the date to get these results
ThanksYou can use StringTokenizer to parse out the months, days and years. Once you do that it's easy to compare them to get the age.
String today = "08/08/1999"
String bDay = "07/10/1977"
StringTokenizer st = new StringTokenizer(today, "/");
String todayMonth = st.nextToken();
String todayDay = st.nextToken();
String todayYear = st.nextToken();Then just do the same thing with bDay and you can compare everything to figure out the age. -
How to calculate age of an equipment
Dear guys,
i need to calculate the age of an equipment, i have birth date of it and usuing info provider 0equipment for reporting.
How to subtract birth date from today? do i need to write a formula? i guess there is no sy-datum in bex.
Should i do it in the cube in update rule?
thanksHi John,
You can use any of these function module in routine to calculate the difference between two dates.
1. HR_HK_DIFF_BT_2_DATES
2. PARAMETER:p_date1 TYPE dats,
p_date2 TYPE dats.
DATA:lv_diff TYPE i.
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = p_date1
i_datum_von = p_date2
IMPORTING
e_tage = lv_diff
EXCEPTIONS
days_method_not_defined = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE:/ lv_diff.
ENDIF.[/code]
3. DAYS_BETWEEN_TWO_DATES
4. HR_99S_INTERVAL_BETWEEN_DATES
5. sd_datetime_difference
Check these links:
[https://forums.sdn.sap.com/click.jspa?searchID=13080683&messageID=5146361]
[https://forums.sdn.sap.com/click.jspa?searchID=13080831&messageID=4479989]
Hope it helps you.
Regards,
Yokesh. -
How to calculate age based on current month and over the next 12 months in Webi 4.1
Hi,
I am working on a report where I need to show employees who turned 65 from the time the report is run to over the next 12 months.I have the 'Date of Birth' field available. I am using Bex Query as a data source and webi 4.1. How do I calculate this in Webi 4.1. I appreciate any help.
Thank you,
Charvi.Hi Charvi,
Get the all employees who are all in 64 age bucket till yesterday. Keep indicator for these employees.
Then obviously these employees will be falling in 65 age in coming 12 months/365 days.
Same you can get at Bex level also. Create formulae :
if employee age = 64 then 1 else 0.
(AGE = 64 * 1 + 0)
Then create condition on this formulae as Value = 1.
Revert back your feedback.
Regards, Vijay -
How to calculate TDS in Oracle HRMS(INDIA)
Hai Guru's
As Iam working on india localisation (payroll) i facing difficulty to calculate income tax details
I Have a dought
TDS generally calculated by accounts department and details is given to hrms department values will be calculated in payroll(AS-IS)
Is there any way to calculate TDS in payroll (oracle apps) if yes please help me out atleast post the material link
IF ANY BODY ME REGARDING THIS ISSUE IT IS A VERY USEFULL
Regards
seemaPl see if ML Doc 556842.1 (Oracle Financials for India Webcast on TDS Regime) can help
HTH
Srini -
I have 2 date fields, date1=01-Aug-70, date2=01-Aug-05, when I use the following statement :
ROUND((date2 - date1) / 365), the result is -64...if seems than system don't know 70=1970 and 05=2005....
How to solve this problems ?.....
Thanks, Urgent!This PL/SQL function was written by me in 1999 which can be used to select from dual or from any database having a date field:
create or replace
FUNCTION date_diff (ddd1 date, ddd2 date) RETURN varchar2 IS
d1 number(2);
m1 number(2);
y1 number(4);
d2 number(2);
m2 number(2);
y2 number(4);
dd1 date:= ddd1;
dd2 date:= ddd2;
feb number(2);
excep exception;
begin
if dd1>dd2 then
raise excep;
end if;
d1:=to_char(dd1,'dd');
m1:=to_char(dd1,'mm');
y1:=to_char(dd1,'yyyy');
d2:=to_char(dd2,'dd');
m2:=to_char(dd2,'mm');
y2:=to_char(dd2,'yyyy');
if substr( to_date('28/02/'||y2,'dd/mm/yyyy')+1,1,2)='29' then
feb:=29;
else
feb:=28;
end if;
if d2<d1 then
if m2 in (2) then
d2:=d2+31;
elsif m2 in (3) then
d2:=d2+feb;
elsif m2 in (4,6,9,11) then
d2:=d2+31;
else
d2:=d2+30;
end if;
m2:=m2-1;
end if;
if m2<m1 then
m2:=m2+12;
y2:=y2-1;
end if;
return
(lpad(y2-y1,3,' ')||'y '||
lpad(m2-m1,2,' ')||'m '||
lpad(d2-d1,2,' ')||'d');
exception
when excep then
return
('wrong*dates');
end;
A handy code I believe, to relieve you of age-calculation problems
CHRISTOPHER
Maybe you are looking for
-
I want to add tags to loops so that they show up in the loop browser in GB. Most of the loops in question are either mine or third party loops. Anybody know this trick? 20" iMac Intel Core Duo Mac OS X (10.4.7) 1.5 GB RAM. 160 & 250 GB LaCie fire
-
Hi, How we will automate and schedule the planing refresh? and What is flat file adapter and Planning adapter? could any one tell ans plz Thanks, Kumar
-
I have a problem connection to app store on iPad2. I get "unknown error" as a message. Any suggestions on what I can do to fix?
-
What are the best tutorial sites to learn java?(Apart from java.sun.com/docs/books/tutorial)
-
Ejecting Tablet from Pavilion x2
how do I safely eject tablet from HP Pavilion x2, it gives me a warning whenever I do this.