Using Joda API to display birth date in months, weeks, days

Hi, I was unable to see a clear sample of the Joda API usage to display a birth day in terms of Months, Weeks, Days.
Has anyone done so?
Thanks,
Say a baby was born on February 2nd 2008, then he is 1 month, 1 week and two days.

DateTime birthday = new DateTime(2008, 2, 2, 0, 0, 0, 0);
DateTime now = new DateTime();
int months = Months.monthsBetween(birthday, now).getMonths();
now = now.minus(Period.months(months));
int weeks = Weeks.weeksBetween(birthday, now).getWeeks();
now = now.minus(Period.weeks(weeks));
int days = Days.daysBetween(birthday, now).getDays();
System.out.printf(
          "The person is %d month(s), %d week(s) and %d day(s)\n",
          months,
          weeks,
          days);~

Similar Messages

  • Display a Date that is 30 days ago from today

    Hi All, I want to display a Date that is 30 days ago from today, and I used Calendar object here is my code,
    Calendar to = Calendar.getInstance();
        String toYYYY = ""+to.get(Calendar.YEAR);
        String toMM = "" + (to.get(Calendar.MONTH) + 1) + "";
        String toDD = "" + to.get(Calendar.DAY_OF_MONTH);
        Calendar from = Calendar.getInstance();
        //I set the date to 30 days ago right here
        from.setTimeInMillis(to.getTimeInMillis() - 1000 * 60 * 60 * 24 * 30);
        String fromYYYY = "" + from.get(Calendar.YEAR);
        String fromMM = ""+ (from.get(Calendar.MONTH));
        String fromDD = ""+from.get(Calendar.DAY_OF_MONTH);
    System.out.println("toYYY is " + toYYYY);
        System.out.println("tomm is " + toMM);
        System.out.println("toDD is " + toDD);
        System.out.println("fromYYYY is " + fromYYYY);
        System.out.println("fromMM is " + fromMM);
        System.out.println("fromDD is " + fromDD);However, the display result is incorrect for the day that is 30 days ago, can somebody tell me what i did wrong, or rather, let me know if I should use something different to get the date that is 30 days ago
    thanks

    [url http://www.javaworld.com/jw-12-2000/jw-1229-dates.html]Calculating Java dates: Take the time to learn how to create and use dates
    [url http://www.javaalmanac.com/egs/java.util/CompDates.html]Comparing Dates
    [url http://www.javaalmanac.com/egs/java.text/FormatDate.html]Formatting a Date Using a Custom Format
    [url http://www.javaalmanac.com/egs/java.text/ParseDate.html]Parsing a Date Using a Custom Format

  • When I add a date to a cell, how can I let another cell display a date that is 30 days later?

    when I add a date to a cell, how can I let another cell display a date that is 30 days later?

    =[cell reference] +30

  • How to display all dates of month in oracle forms..pl send full code

    hai every one.
    i have multiple rows of block.
    i want to display all dates in that block.

    Hello,
    +1. Complete Forms Solution described in the Dynamic poplist in a multi-record item. thread.+
    This solution is based on dynamic list population with appropriate predefined record group (the number of such predefined record groups could be rather big --> 1 Continents*Countries.+
    Record Groups can be totally dynamic, so you don't need to have them pre-existing at runtime.
    Francois

  • Split Data from Month to Days in the Bex Report

    Hi Gurus,
    I have a Actual and Plan data. Actual data is on daily basis and Plan data is in monthly basis.....
    Requirement is : User will be entered Calendar Day ( any day of the month for example : 06/18/2010)  to bring Month to date on both Actual and Plan data. Like for example if user enters the date 18th June 2010. Then I need to pull from the beginning of the month to date up to that selection day( in our case 18 days).
    Actual : I don't have issue getting the Month to date and Year to date because I have data on daily basis.
    Plan : As I said data is on monthly basis. I want to break this data up to the day selected ( from 1st of the June month to 18th as given in example) by user. Like if you have amount is $5000 then my logic will be
    CKF  =  (5000 * 18) / total number days in the month
    Please provide help on this how to bring the data for Plan...
    Thanks
    Ganesh Reddy.

    ganesh,
    in your data model convert date field to calander period and calander year .
    once that is done
    create restricted key figures
    1) month to date
    2) year to date
    month to date - key figure is restricted to custom variable ( which populates calander period based on the date user enter)
    year to date - key figure is restricted to custom variable (which populates calander year based on the date user enter )
    hope you got it .
    Thanks,
    pk.

  • How to use global classes and display returned data?

    Hello experts,
    I have the following code in a program which accesses a global class (found in the class library). It executes one it's static methods. What I would like to do is to get hold of some elements of the returned data. How do I do that please?
    Your help is greatly appreciated.
    ***Use global class CL_ISU_CUSTOMER_CONTACT
    DATA: o_ref TYPE REF TO CL_ISU_CUSTOMER_CONTACT.
    DATA: dref_tab LIKE TABLE OF O_ref.
    DATA: begin OF o_ref2,
    CONTACTID               TYPE CT_CONTACT,
    P_INSTANCES             TYPE string,
    P_CONTEXT               TYPE CT_BPCCONF,
    P_CONTROL               TYPE ISU_OBJECT_CONTROL_DATA,
    P_DATA                  TYPE BCONTD,         "<<<=== THIS IS A STRUCTURE CONTAINING OTHER DATA ELEMENTS
    P_NOTICE                TYPE EENOT_NOTICE_AUTO,
    P_OBJECTS               TYPE BAPIBCONTACT_OBJECT_TAB,
    P_OBJECTS_WITH_ROLES    TYPE BAPIBCONTACT_OBJROLE_TAB,
    end of o_ref2.
    TRY.
        CALL METHOD CL_ISU_CUSTOMER_CONTACT=>SELECT  "<<<=== STATIC METHODE & PUBLIC VISIBILITY
          EXPORTING
           X_CONTACTID = '000001114875'   "Whatever value here
          RECEIVING
            Y_CONTACTLOG = o_ref
    ENDTRY.
    WHAT I WOULD LIKE TO DO IS TO MOVE o_ref TO o_ref2 and then display:
    1) P_DATA-PARTNER
    2) P_DATA-ALTPARTNER
    How can I do this please?

    I now have the following code. But when I check for syntax I get different error. They are at the end of the list.
    Here is the code the way it stands now:
    ================================================
    ***Use global class CL_ISU_CUSTOMER_CONTACT
    DATA: oref TYPE REF TO CL_ISU_CUSTOMER_CONTACT.
    DATA: dref_tab LIKE TABLE OF oref.
    DATA: begin OF oref2,
    CONTACTID TYPE CT_CONTACT,
    P_INSTANCES TYPE string,
    P_CONTEXT TYPE CT_BPCCONF,
    P_CONTROL TYPE ISU_OBJECT_CONTROL_DATA,
    P_DATA TYPE BCONTD,      "THIS IS A STRUCTURE CONTAINING OTHER DATA ELEMENTS
    P_NOTICE TYPE EENOT_NOTICE_AUTO,
    P_OBJECTS TYPE BAPIBCONTACT_OBJECT_TAB,
    P_OBJECTS_WITH_ROLES TYPE BAPIBCONTACT_OBJROLE_TAB,
    end of oref2.
    TRY.
    CALL METHOD CL_ISU_CUSTOMER_CONTACT=>SELECT     " STATIC METHODE & PUBLIC VISIBILITY
    EXPORTING
    X_CONTACTID = '000001114875' "Whatever value here
    RECEIVING
    Y_CONTACTLOG = oref
    ENDTRY.
    field-symbols: <FS1>      type any table,
                   <wa_oref2> type any.
    create data dref_tab type handle oref.   " <<===ERROR LINE
    assign dref->* to <FS1>.
    Loop at <FS1> assigning  <wa_oref2>.
    *use <wa_orfe2> to transfer into oref2.
    endloop.
    write: / 'hello'.
    =========================================
    Here are the errors I get:
    The field "DREF" is unknown, but there is a field with the similar name "OREF" . . . .
    When I replace itr by OREF I get:
    "OREF" is not a data reference variable.
    I then try to change it to dref_tab. I get:
    "DREF_TAB" is not a data reference variable.
    Any idea? By the way, must there be a HANDLE event for this to work?
    Thanks for your help.

  • Using a datagrid to display XML data

    Hello,
    I'm binding xml to a datagrid but I'm having trouble displaying some of the data.  Here's my example.
    Here's my test data:
    [Bindable]
    private var test:XML =
      <vm:validationMessages xsi:schemaLocation="http://www.location.com/2.0 http://schemas.com/2.0.0/valMessages.xsd" severity="ERROR" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vm="http://www.location.com/2.0" xmlns:zucc="http://www.location.com/results/1.0">
      <vm:validationMessage severity="ERROR" errorCode="ErrorType1" url="www.loc.com">
        <vm:messageDetail>Text I want to return</vm:messageDetail>
      </vm:validationMessage>
    </vm:validationMessages>
    I've set the default namespace here:
    public static const vm:Namespace = new Namespace("http://www.location.com/2.0");
    default xml namespace = vm;
    And here is the datagrid definition:
    <mx:DataGrid x="10" y="30" width="738.5" height="189" id="dgValidation" dataProvider="{test.validationMessage}">
      <mx:columns>
        <mx:DataGridColumn headerText="Severity" dataField="@severity"/>
        <mx:DataGridColumn headerText="Error Code" dataField="@errorCode"/>
        <mx:DataGridColumn headerText="Url" dataField="@url"/>
        <mx:DataGridColumn headerText="Description" dataField="messageDetail"/>
      </mx:columns>
    </mx:DataGrid>
    The attributes "severity, errorCode, url" are being displayed correctly, however "messageDetail" will not display.  I've tried several different ways of calling it with no luck. Is there a way to do this?
    Thanks.

    To solve this problem I had to use labelFunction.  The working line was this:
    <mx:DataGridColumn headerText="Description" labelFunction="dataGrid_labelFunc"  dataField="messageDetail"/>
    The function looks like this:
    private function dataGrid_labelFunc(item:XML, col:DataGridColumn):String {
         var qN:QName = new QName(vm, col.dataField);
         return item[qN].text();

  • CAN program using Channel API doesn't receive data

    Hello everyone,
    I'm get in stuck. I'm currently programming CAN interface for a transmission using PXI, Channel API and a .dbc file.
    CAN configuration based on .dbc file is downloaded to PXI by MAX. 
    The problem is that it receives 0 for all the values by Channel API based program (Attached file), though it seems receiving meaningful data when I check raw data by Frame API based program. 
    Baudrate, CAN port, and .dbc file are correct.
    thanks! 
    Attachments:
    All signals and values.vi ‏22 KB

    Hi Yuta
    What I am expecting is that the sample rate is being set to high. When using the multiple channel - single sample instance of the CAN read vi, it will return a single sample for every period. The number of samples to read input is actually ignored and it will return a single sample for every channel specified. Therefore, if no data has been received within the sample period specified with the sample rate, it will return the default value as specified in the database file.
    Due to the high sample rate, it might be that data is being received, but aren't visible on screen since they are quickly being overwritten by new (default) data. I suggest trying to use the Multiple Channels - Multiple Samples instance of the CAN Read vi to see if you receive values in this case. Or you could try lowering the sample speed (note that sample rate is not the same as CAN baud rate).
    Also, make sure you are properly reading the data already in MAX's test panel as this would indicate if the database file is loaded properly.
    Best Regards
    Michiel
    Applications Engineer
    NI Belgium
    http://www.ni.com/ask

  • Using Flex/PHP to Display MYSQL data and Images

    Does anyone have any good examples of using Flex 3 in conjunction with PHP to display data and images from a mysql database? I've searched a lot and it seems hard to find this combination. I have manged to create a login system using this which allows users to login via usernames and passwords that are stored in my mysql database (Grizzz helped me out a lot with this).
    But I now want to create a product selection in the site with the categories down the left hand side and the products related to these categories displayed in the other panel once each of these products are clicked. The guy I'm making it for wants to be able to add and delete categories as well as add and delete products so obviously it needs to be done using php and mysql. I'm looking for something similar to the way the online shop is laid out in the following example:-
    https://www.whitestonecheese.co.nz/Radshop/bin/Whitestone.html
    Thanks for any suggestions.

    To solve this problem I had to use labelFunction.  The working line was this:
    <mx:DataGridColumn headerText="Description" labelFunction="dataGrid_labelFunc"  dataField="messageDetail"/>
    The function looks like this:
    private function dataGrid_labelFunc(item:XML, col:DataGridColumn):String {
         var qN:QName = new QName(vm, col.dataField);
         return item[qN].text();

  • ST03 displays statistics data just for two days ago

    Dear All,
    I'm a newbie in sap.
    In my SAP SOLMAN server, there's no statistical record when I enter STAD for today.
    And, inside ST03, last workload records was two days ago.
    I've checked that the SAP_COLLECTOR_FOR_PERFMONITOR scheduled per hour and finished successfully. I've also tried to restart the SAPOSCOL, upgrade to the newest SAPOSCOL, but the problem is still occured.
    Several days ago, I deleted the Statistic Records using ST03, hope it would refresh the statistics, but the new statistics only created for a few hours, then it stopped, and continued the next two days with old two days data.
    How to make this back to normal ?
    Any suggestions?
    Thank you very much

    Hi
    Check your client time setting
    it  is European timing  change in India times
    through SPRO
    it is help out
    Regards
    Jay

  • Birth date shifts back 1 day when changing time zones

    I live in China temporarily, but I come back to the US frequently. China is 15 hours ahead of the Mountain time zone in which I currently am. This trip, many of my birthdays were listed a day earlier in Address Book, thus being reflected incorrectly in iCal. Why would this happen? And how can I prevent it??? Very annoying!!

    Amaneta,
    this happened to me too once when traveling between EU and US, it was not the date that changed but all my appointments shifted 10 hours in iCal and Palm.
    Can't remember if there was a solution posted but I changed my Mac time to CET, installed a backup from the previous day on my Palm and deleted the iCal appointments before doing a sync with the Palm.
    Scary stuff for sure. See if just changing back the time to China time solves your problem (at least partly, you will not be in sync with US time), uncheck automatic time zones in Preferences/Date&Time

  • For a given date required  last week day

    Hi Friends,
                    Is there any function module exists if I will enter any date as input parameter
    the last thursday date should come as output ?
    For example 1: The input parameter is 15.04.2009 (15th is Wednesday) so the output is 09.04.2009(bcz last thrusday is 9th)
    2. Suppose if the input parameter is 17.04.2009 (17th is friday) so the output is 16.04.2009(bcz last thrusday is 16th)
    Thanks
    Raj

    Hi ,
    You can use the following code:
    data : v_date type datum,
             v_day(10) type c.
    v_date = pass whatever date you want in format yyyymmdd .
    do .
    CALL FUNCTION 'DATE_TO_DAY'
      EXPORTING
        date          = v_date
    IMPORTING
       WEEKDAY       = v_day
    if  v_day <> 'Thursday'.
    v_date = v_date - 1 .
    else.
      write:  v_date .
    exit.
    endif.
    enddo.
    Regardrs,
    Ashish Arora

  • IOS 7.0.3 week bug (show right date but wrong week day)

    Hi, when you open calendar (week view) in iOS 7 the day appers right but the week day (monday for example) appers plus one.
    Example: today is 29th (Tuesday), if you open week view the 29th points to Wednesday, wired no?
    Regards,
    Leonardo Bissoli.

    I noticed that on my phone today (4s) and my son's (5s). The Red line indicates the correct time, but the location on the day view of the calendar is incorrect. I've reported this via Apple feedback, maybe you could do the same. www.apple.com/feedback and click on the appropriate link.

  • How to Limit the Displaying of Data Using PointTheme over the map

    Hi,
    I have the following requirement, which i'm trying to implement with <dvt:map & <dvt:PointTheme components.
    *The requirement is ... I have a base map, which is being accessed via <dvt:map component. And i'm using point theme to display certain data over the map. Let us consider, over the US map ... i'm displaying 24 points(for each polygonone point .... taking the centroid of each polygon) when the map zoom level is 0.
    At this zoom level '0', user can see all 24 points. But when the user start clicking on '+' to Zoom In(Now the zoom level is '1'), at this zoom level user can see only 18 points. User can see the remaining 6 points by dragging the base map to either sides.
    This mean, irrespctive of the zoom level the point theme is rendering the all the points over the map. Instead, i would like to display the data specific to the polygons that are visible to the user. At zoom level '0', if the user is able to see all the polygons, then display all 24 points. And at zoom level '1'...if the user is able to see 18 polygons and then display only those 18 points. And if the user tries to see the other polygons data ... user may drag the base map either sides. In that case, the point theme should render data specific to the polygons that the user is able to see.
    Similarly, if the user is at zoom level '2'...at this zoom level user is able to see 13 polygons over the IE. so the point theme should render only 13 points specific to each polygon. If the user tries to do dragging the base map either sides...then display the points, specific to the polygons that the user is able to see.
    Similarly for other zoom levels ... Please let me know if you require any other information.
    Thanks & Regards,
    Kiran Konjeti

    You'll need to do a little software workaround on the values you read from your counter.   But first a little tutorial to explain *why*.
    The E-series boards use 24-bit counters.  When LabVIEW requests an integer count value, the count is returned in a 32-bit unsigned integer datatype, where the 24 lowest bits represent the value in the board's count register.  The upper 8 bits are *always* 0's.
    The count register can increment from 0 to 16 million plus (2^24 - 1), then it must "roll over" back to 0 again just like an odometer.  Similarly, when it decrements past 0, it next goes to the max value of 2^24 -1 as you observed.
    So we need a little software workaround that'll convert (2^24 -1) to (-1) and (2^24 -2) to (-2), etc.  The way to do it is to first detect whether the highest bit is a 1.  One way is to compare whether the count value is >= 2^23, making sure to use integers to do the comparison.  Whenever the value is >= 2^23, subtract 2^24 from it to create your new count value which will then decrement 3,2,1,0,-1,-2,-3, etc. as desired.
    Here's a link to a similar explanation.  Couple more notes too.  First, if this is a continuously rotating encoder, you may still encounter a discontinuity when the revised count value crosses the +/- 2^23 boundary.   Second, direct connection of a quadrature encoder to an E-series board isn't recommended because of unrepeatability when measureing direction changes.
    -Kevin P.

  • Access content and metadata stored in VCR using SP1 api in weblogic Portal

    Hi
    I have configured Virtual Content Repository (VCR), I am able to see all the contents in VCR, that is stored in Oracle UCM. I need to know how I can get the content and metadata of the stored content using SPI api and display the metadata of contents present in a particular folder and display it in weblogic portal.
    Please provide any sample code how to acess that also helap me a lot.
    Edited by: user10934682 on Apr 19, 2011 1:39 AM

    To get started, you might want to look at the CM JSP tag library. With this tag library, it's straight forward to fetch a content Node and display the data. See the following tag lib documentation: http://download.oracle.com/docs/cd/E15919_01/wlp.1032/e14256/content/cm/tld-summary.html
    The tag doc includes some sample code showing the usage of the tags.
    For more advanced, or non-JSP usage, see the javadoc for com.bea.content.federated package. http://download.oracle.com/docs/cd/E15919_01/wlp.1032/e14255/com/bea/content/federated/package-summary.html
    Brad

Maybe you are looking for

  • No remittance advice output in the 'Outbound Payment File Directory'

    We are working on an upgrade from 11i to R12. Configuration has created a profile for an electronic payment with a separate remittance advice. They have specified an outbound payment file directory. The EFT text file is generated in the proper direct

  • Everytime I close my laptop, and then re-open it later, it automatically has logged me back into my account. Why is this?

    Hi, So, normally when I close my laptop after usage (putting it in sleep mode) it will automatically log it out of the account I am using. Whenever I want to go back into it, I have to type in my password before getting back in. However, every time I

  • How to adjust for distorted colors printing on HP 8500 A909g.

    In regard to HP All In One 8500 A909g.  Photos look great on computer screen but print with an overall red hue.  I can eventually adjust the color to get a good print but it wastes a lot of ink getting there.  Why doesn't my printer print the colors

  • Space used up by my objects

    I am working on a oracle 10g database with many database users of which I have access to only six of them ,due to space contention issues I need to know which how much space the objects which are created under my db user occupy , is there any query w

  • Multiple user id per user

    HI guys we are implementing concurrent employement solution of SAP. Under that solution in certain circumstance user will be having multiple sap id. My question is ... Is CC 5.2 capable of reporting SOD conflicts taking into a/c all the sap id of use