Calculate age and next birthday

My Genius friend did this and i thought i should share........
import java.util.*;
import java.io.*;
import java.text.*;
public class Ex1804A
     public static void main ( String []args )
          BufferedReader in = new BufferedReader ( new InputStreamReader ( System.in ) );
          SimpleDateFormat sdf = new SimpleDateFormat ("d/M/y");
          Calendar birthCal = new GregorianCalendar();
          Calendar current = new GregorianCalendar();
          System.out.println ( "birthday calculation\nEnter 'end' to exit" );
          Date birthday;
          try
               while ( true )
                    System.out.print ( "Enter birthday date:\t" );
                    String input = in.readLine ();
                    if ( input.equals ("end"))
                         break;
                    try
                         birthday = sdf.parse (input);
                         birthCal.setTime (birthday);//set Calendar to Calendar of birthday
                         int currentYear = current.get (Calendar.YEAR);
                         int age = currentYear - birthCal.get (Calendar.YEAR);//get age
                         birthCal.set ( Calendar.YEAR, currentYear );//set Year to current year
                         if ( current.after ( birthCal ) )//if birthday already finished,
                         {     age++;//add one to age
                              birthCal.add ( Calendar.YEAR, 1 );//add one to next birthday year
                         Date d = birthCal.getTime(); //get date of next birthday
                         System.out.println ("\tnext birthday :\t" + sdf.format(d));//need to format
                         System.out.println (" Age next birthday;\t" + age);
                         System.out.println ();
                    catch (ParseException e)
                         System.out.println ("Invalid date. Please enter again.");
          catch (IOException e )
               System.out.println ("IO Exception ");
}

Hi,
Show date format for user input.
import java.util.*;
import java.io.*;
import java.text.*;
public class Ex1804A
public static void main ( String []args )
BufferedReader in = new BufferedReader ( new InputStreamReader ( System.in ) );
SimpleDateFormat sdf = new SimpleDateFormat ("dd/MM/yyyy");
Calendar birthCal = new GregorianCalendar();
Calendar current = new GregorianCalendar();
System.out.println ( "birthday calculation\nEnter 'end' to exit" );
Date birthday;
try
while ( true )
System.out.print ( "Enter birthday date (dd/mm/yyyy):\t" );
String input = in.readLine ();
if ( input.equals ("end"))
break;
try
birthday = sdf.parse (input);
birthCal.setTime (birthday);//set Calendar to Calendar of birthday
int currentYear = current.get (Calendar.YEAR);
int age = currentYear - birthCal.get (Calendar.YEAR);//get age
birthCal.set ( Calendar.YEAR, currentYear );//set Year to current year
if ( current.after ( birthCal ) )//if birthday already finished,
{ age++;//add one to age
birthCal.add ( Calendar.YEAR, 1 );//add one to next birthday year
Date d = birthCal.getTime(); //get date of next birthday
System.out.println ("\tnext birthday :\t" + sdf.format(d));//need to format
System.out.println (" Age next birthday;\t" + age);
System.out.println ();
catch (ParseException e)
System.out.println ("Invalid date. Please enter again.");
catch (IOException e )
System.out.println ("IO Exception ");
} Regards,
Ram.

Similar Messages

  • How to calculate the number of days until your next birthday. Only using current month, day and birth month and day.

    I'm trying to calculate the number of days until your next birthday. Only using current month, day and birth month and day. I can get close but i'm way off. When i enter in the next day, the amount of days is supposed to be 364. This is where I am having problems. I know my code is way off. I just need some guidance please!
    Attachments:
    D5.7_1.vi ‏8 KB

    I just had a little fun with the Time Record...
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    D5.7_1_BD.png ‏19 KB

  • 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?
    thanks

    Hi,
    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

  • Aging and Auto Refresh

    Hi
    I read from one of the previous threads that "Even if rows are aged out by the aging mechanism, if those rows still exist in Oracle they will simply be pushed back to the cache on the next AUTOREFRESH." Aging is to remove data that is no longer needed. So, if autorefresh keeps updating TimesTen with the already aged out data, Cant aging and autorefresh co-exist to achive this purpose?
    Thanks..

    Ageing policy in TimesTen (TT) can vary depending on your set up. In general ageing is there to get rid of unused data (based on LRU ageing, Time-based ageing etc). I believe the ageing process can also be usage based. For example remove Least Recently Used data when database usage passes > 90% threshold. Since in normal operations, there is finite size to TimesTen DataStore and TempStore and disk resident databases (DRDB) have a habit of growing then TT has no choice except getting rid of the old data.
    In normal operations probably you will deploy Incremental Autorefresh whereby Oracle tracks changes and periodically updates only the rows in the cache group that have changed in Oracle's DRDB. If that is the case then those updated rows will end up in MRU section of the cache again and will not be deleted.
    I think the best cache strategy is to use something like DYNAMIC ASYNCHRONOUS WRITETHROUGH GLOBAL CACHE GROUP where data from corresponding Oracle tables will be loaded into TT on request. So this is loading data on demand which is kind of useful as the first load would be slow (replication getting rows from Oracle DRDB table into TT table). However, subsequent references in TT to the row will be fast as by then the row is already in TT's cache. In real life scenario, TT only gets data as it is needed and it deletes data as it does not need.
    HTH,
    Mich

  • Safari blank page or loading for ages and then timeout!

    Hi, this is my first topic so please any reply would be much appreciated. I had a week holiday when my Mac was switched off. Before that I havent noticed any problem with it, everything was working fine and fast. I came back on the 1st, had some updates installed on the 2nd and since then I barely can search the web. The pages loading for ages, after that sometimes get info that Im not connected to the web or timeout or the server doesnt respond to that website. BUT my Skype is still fine I even had a two way video call and was perfectly working. 1st I thought it was Safari so I downloaded Mozzilla but I had the same issue with that. Sometimes Safari works ok for a while and then all of a sudden just try to go to another page from what I used and was ok and that new page just doesnt load. I emptied the cache, I reset Safari and after that my topsites never work again. Well not never but once I used something from there I will not be able to go back and use another one. Since the reset I cant even see all the icons in my TOPSites. This problem is killing me now, dont really now what to do, this is my first Mac and I bought it last october. Still have plenty to learn.
    My Safari version is 4.0.5.
    thanks

    HI and Welcome to Apple Discussions...
    Since you have already emptied the cache and reset Safari...
    Go here for trouble shooting 3rd party plugins or input managers which might be causing the problem. Safari: Add-ons may cause Safari to unexpectedly quit or have performance issues
    Right or control click the Safari icon in the Applications folder, then click: Get Info In the Get Info window click the black disclosure triangle next to General so it faces down. *Make sure Safari is NOT running in Rosetta.*
    

Web pages now include a small icon or 'favicon' which is visible in the addrMss bar and next to bookmarks. These icons take up disk space and slow Safari down. It is possible to erase the icons from your computer and start fresh. *To delete Safari's icon cache using the Finder, open your user folder, navigate to ~/Library/Safari/ and move this file "webpageIcons.db to the Trash.*
    If you still have problems with Safari, go to the Safari Menu Bar, click Safari/Preferences. Make note of all the preferences under each tab. Quit Safari. Now go to ~/Library/Preferences and move this file com.apple.safari.plist to the Desktop. Relaunch Safari. If it's a successful launch, then that .plist file needs to be moved to the Trash.
    Carolyn

  • How to include the Age and Age operator in Dashboard prompts

    I wouild like to create two new dashboard prompts 'Age' and 'Age Operator' both as drop downs.
    The 'Age' prompt should have the values from 1-100 as dropdown for the users to select from.
    The 'Age Operator' should have the values <, <=, >, >=, = as dropdown for the users to select.
    I have PERS_DOB column in Person table. I do not have any operator values stored in any tables.
    How can I create these two dashboard prompts so that the user can select the values from the
    dropdown list and filter the results against.
    For example:
    User select Age 20 from Age dropdown prompt and '<' from the Age operator prompt the results
    should filter based on the above and should get us the records for the people whose
    Age is less than 20.
    I appreciate any help on this.
    Thanks.

    You could try this:
    1) For the "age operator" prompt, use words to describe the operators (e.g., "less than" rather than the symbol <=, etc.). (I'll assume you know how to build the prompt using CASE statements and UNION. It's pretty straightforward.)
    2) Build 5 small reports, one for each operator, that only returns a row when the particular operator is selected in the prompt. Each of these reports will be in the guided navigation of a separate section.
    3) Now, build 5 versions of your report with a filter on the "Age" prompt, one report that calculates the 5 different permutations of the age chosen (i.e., less than prompt, less than or equal to prompt, etc.) and put each report in the guided navigation section that corresponds to the applicable small report you built in step 2. So, for example, for the section that returns a row when "less than" is chosen, put the report that filters for "age less than 'age prompt'."
    So here is how it works: When the user selects an age and operator, only the section that corresponds to the operator selected will display because of the guided navigation. The other 4 sections will not show, because the small report in the guided navigation part of the section will return no rows.

  • 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 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
    Manu

    Manu 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 AUTOEXTEND ON NEXT in tablespace clause

    hi
    Please explain How to calculate AUTOEXTEND ON NEXT in tablespace clause.
    whether AUTOEXTEND ON NEXT 50M or 100M or 500M
    Thanks

    174313 wrote:
    hi
    Please explain How to calculate AUTOEXTEND ON NEXT in tablespace clause.
    whether AUTOEXTEND ON NEXT 50M or 100M or 500M
    ThanksThe autoextend size depends on the following :-
    1) Tablespace type Dictionary managed (DMT) or Locally managed (LMT)
    2) Segment space management manual or Auto.
    3) Extent allocation management Autoallocate or uniform.
    If your tablespace is Locally managed with segment management Auto (ASSM) and with extent management is uniform , the autoextend size will be uniform for all the extents , initial and next extents all will be uniform size .
    If your tablespace is Locally managed with segment management Auto (ASSM) and with extent management is autoallocate, Oracle will size the extents automatically starts with 64KB and can go upto 64MB.
    If you have dictionary managed tablespace you will specify the next size at tablespace creation.
    Hope this helps.

  • Calculate Age in an ABAP report

    Hi all you wonderful SAP people,
    I am trying to calculate age in my ABAP report,
    Any function module I can use or code snippet? Your help is much appreciated. Points will be awarded.
    Regards
    Ramorua

    Hi Mohamed,  some characters (plus signs, and spaces around the minus) seem to have gotten lost from your code, maybe during the conversion of the forum. Also, the data type is i, not int.
    Header 1
          DATA: lv_age TYPE i.
          lv_age = sy-datum(4) - lv_birthdate(4).
          IF sy-datum+4(4) LT lv_birthdate+4(4).
            lv_age = lv_age - 1. " or SUBTRACT 1 FROM lv_age.
          ENDIF.

  • To calculate age

    need to create object to calculate age of an employee when he employed using two columns i.e. date of employment and dob, both columns are in different table.
    how to do that?
    let me know if you need more info
    thanks & regards

    Hi,
    1.In Universe _First create the objects with DOE(Date of employeement), DOB(Date of Birth) as a Date object and right click on those objects and set the Object format as Date/Time YYYY. Click on Add for both objects. and Create one more object and select the Object as
    Sum(@Select(Employee/DOE)-@Select(Employee/DOB))
    2. In Web I_ same like above, 2 objects  creation and apply the Fromat in Universe and Web I create a variable with some name as age and in that
    =Sum(DOE-DOB)
    Click ok.
    Hope it will help you...
    All the Best,
    Madhu....

  • Query to calculate age

    Hi
    Please suggest me to wirte a function which can calculate age.

    Hi,
    No need of function. Just simple calculation.
    SQL> select round(months_between(sysdate,to_date('11-MAY-1977','dd-MON-YY'))/12) age from dual;
           AGE
            33If you are taking in account the dates stored in a date column of oracle table then do take care of the years
    before and after 1950.
    A thread for your reference: Re: date airthmetic

  • HT5312 My email associated with my iCloud ID has been deleted and my birthday is wrong in the system for the security question. Therefore, I can't delete my old iCloud ID in order to have my new ID on my phone.

    My email associated with my iCloud ID has been deleted and my birthday is wrong in the system for the security question. Therefore, I can't delete my old iCloud ID in order to have my new ID on my phone. HELP!

    If the old ID is yours, and if your current ID was created by editing the details of this old ID (rather than being an entirely new ID), go to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iDevice, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • Calculate age using DOB

    Is there a way to calculate age from DOB in the RPD business model layer? In the table, there is only DOB stored in string format (e.g. 19700125, YYYYMMDD format) and we need to dervie age in the RPD.

    Here's a hint:
    use TimestampDiff funtction
    such as TimestampDiff (SQL_TSI_YEAR, date1, now() )
    You might have to use CAST function to turn your column into date type....
    I hope this is helpful.

  • Any reason why my MacBook Pro keeps dropping the WiFi signal - will be fine for ages and then just drops it!, Any reason why my MacBook Pro keeps dropping the WiFi signal - will be fine for ages and then just drops it!

    Any reason why my MacBook Pro keeps dropping the WiFi signal - will be fine for ages and then just drops it! Does it at home and work so not either broadband connection

    jp270759 wrote:
    Hi. MAny thanks for the answer. Am new to Apple - what's the "real" MacBook Pro forum?
    I would like to know also!
    For your issue - Solution may be found if you search in the "More Like This" section over in the right column.
    Change your router channel.  Sometimes this is all you will have to do.
    Power cycling the router.  Read the router's user manual or contact their tech support for instructions.
    System Preferences/Internet & Network/Network
    Unlock the padlock
    Locations:  Automatic
    Highlight Airport
    Click the Assist Me button
    In the popup window click the Diagnostic button.
    System Preferences/Network- Unlock padlock.  Highlight Airport.  Network Name-select your name.  Click on the Advanced button.  Airport/Preferred Networks-delete all that is not your network.
    Place a check mark next to "Remember networks this computer has joined."  Click the OK button and lock the padlock.  Restart your computer.
    http://support.apple.com/kb/TS1920 Mac OS: How to release and renew a DHCP lease
    No internet connection (wireless)
    Check to see if an extra entry is present in the DNS Tab for your wireless connection (System Preferences/Network/Airport/Advanced/DNS).
    Delete all extra entries that you find.
    Place a check mark next to "Remember networks this computer has joined."
    Other resources to check into:
    Troubleshooting Wi-Fi issues in OS X Lion and Mac OS X v10.6
    Netspot
    How to diagnose and resolve Wi-Fi slow-downs
    Pv6 troubleshooting
    Mac OS X 10.6 Help:  Solving problems with connecting to the Internet
    What Affects Wireless Internet?
    Solutions for connecting to the Internet, setting up a small network, and troubleshooting

Maybe you are looking for

  • If condition statement not working in jsp scriptlet

    <% String hostName = java.net.InetAddress.getLocalHost().getCanonicalHostName(); if(hostName.endsWith("dinesh.com")) System.out.println("it works"); else { System.out.println("it doesn't work"); %> I am getting output as it works & it doesn't work. I

  • Portal Freezes when interactive form drop down is selected..

    Hi Experts, We are facing a strange problem with the drop downs in interactive form. We developed an interactive form with dynamic internal tables and Automatic dictionary search helps attached. Before upgrading SAP SP 27 we were able to use it witho

  • Firefox wont load search engines

    i have run spyware terminator and have cleared cache files and have disabled add-ons and this has made no difference. I'm starting to get a little annoyed can anyone help

  • E-mail portlet - using OID user info

    I am looking to write or re-use a portlet for sending e-mails. I want the e-mail 'From' to be automatically populated by the Portal user's definition in OID. Is this information available through the Portal APIs ? The plsql API wwsec_api.person_info

  • NOTEBOOK STANTDARD OPERATING TEMPERATURES

    IS THESE TEMPERATURE OK AT IDLE STATE CPU 46 °C (115 °F) CPU Package 45 °C (113 °F) CPU IA Cores 45 °C (113 °F) CPU GT Cores 45 °C (113 °F) CPU #1 / Core #1 45 °C (113 °F) CPU #1 / Core #2 44 °C (111 °F) TOSHIBA MQ01ABD075 36 °C (97 °F) Product name: