Date difference in years,month,days should consider Leap Year

I would like to know how to compute the difference between two Date, and get the difference in years,months,days, PS. Should include New Year
Eg Date1 : 01/01/2000
Date2: 01/01/2005
Diff: years=5, months=0 days=1 for a leap year is included'2004'

I would like to know how to compute the difference
between two Date, and get the difference in
years,months,days, PS. Should include New Year
Eg Date1 : 01/01/2000
Date2: 01/01/2005
Diff: years=5, months=0 days=1 for a leap year is
included'2004'If any program I was using gave me that result, I would consider it a bug.

Similar Messages

  • Display dates with zeros for month, day, year.

    I have a date coming from a database as an int (20021215 means 12/15/2002). If the database gives me a "0", meaning no date value is assigned, then it should be displayed as "00/00/0000". The following code snippet works for the non-zero int database values ...
    public static String formatDisplayDate(int date) {
        String dateAsString = null;
        if (date == 0) {
            dateAsString = "00000000";
        else {
            dateAsString = Integer.toString(date);
        String strYear = dateAsString.substring(0,4);
        String strMonth = dateAsString.substring(4,6);
        String strDay = dateAsString.substring(6);
        int year = Integer.parseInt(strYear);
        int month = (Integer.parseInt(strMonth)) - 1;
        int day = Integer.parseInt(strDay);
        DateFormat myFormat = DateFormat.getDateInstance(DateFormat.SHORT);
        Calendar cal = myFormat.getCalendar();
        cal.set(year, month, day);
        Date myDate = cal.getTime();
        String formattedDate = myFormat.format(myDate);
        return formattedDate;
    }Although I didn't really expect the zero values case to work, I am not sure how to implement it. How would I go about building a string using all zeros and still have it automatically display in the correct locale format?
    Any help is appreciated.

    Thank you for your response. I agree a blank field would be better, but I think the "zeros" format is there to give the user an idea of expected date entry formatting, not that they'll necessarily follow it. I have made a few changes per your suggestions (shown below for the record, minus the exception handling), and it works perfectly.
    public static String formatExternalDate8(int date) {
      String dateAsString = null;
      if (date == 0) {
        dateAsString = "00010101";
      else {
        dateAsString = Integer.toString(date);
      int year = Integer.parseInt(dateAsString.substring(0,4));
      int month = (Integer.parseInt(dateAsString.substring(4,6))) - 1;
      int day = Integer.parseInt(dateAsString.substring(6));
      DateFormat myFormat = DateFormat.getDateInstance(DateFormat.SHORT);
      Calendar cal = myFormat.getCalendar();
      cal.set(year, month, day);
      Date myDate = cal.getTime();
      String formattedDate = myFormat.format(myDate);
      if (date == 0) {
        formattedDate = formattedDate.replace('1', '0');
      return formattedDate;
    }Thanks again for your assistance.

  • Find year,month & day between dates

    Hi,
       I need to find a number of years, months & day between a given dates. For example If a employee joined on 31.01.2003 and left on 01.06.2006, I need to find in between how many years, months & days he has worked. Is there any function module available .

    DATA: EDAYS LIKE VTBBEWE-ATAGE,
    EMONTHS LIKE VTBBEWE-ATAGE,
    EYEARS LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
    TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    Call Function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
    *   I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Using teh abiove u can get difference but when u pass previous year u wont get the exact.
    There is no seperate FM for this, u have to use three FM.
    If possible using these three FM code u can create an FM.
    <b>For years and months between two days:</b>
    DATA:   EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE PREL-BEGDA,
                     TODATE   LIKE PREL-BEGDA DEFAULT SY-DATUM.
    CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES'
      EXPORTING
        first_date                        = fromdate
    *   MODIFY_INTERVAL                   = ' '
        second_date                       = todate
    IMPORTING
       YEARS_BETWEEN_DATES               =  EYEARS
    * EXCEPTIONS
    *   SEQUENCE_OF_DATES_NOT_VALID       = 1
    *   OTHERS                            = 2
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Write:/ eyears.
    DATA:       EMONTHS LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE SY-DATUM,
                TODATE   LIKE SY-DATUM
    DEFAULT SY-DATUM.
    CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
      EXPORTING
        i_datum_bis         = fromdate
        i_datum_von         = todate
    *   I_KZ_INCL_BIS       = ' '
    IMPORTING
       E_MONATE            = emonths
    write:/ emonths
    CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
    EXPORTING
    I_DATUM_BIS = x_faede-zfbdt
    I_DATUM_VON = p_fdat
    I_KZ_EXCL_VON = '0'
    I_KZ_INCL_BIS = '0'
    I_KZ_ULT_BIS = ' '
    I_KZ_ULT_VON = ' '
    I_STGMETH = '0'
    I_SZBMETH = '1'
    IMPORTING
    E_TAGE = dias_v.
    IF SY-SUBRC <> 0.
    ENDIF.
    x_faede-zfbdt -> 20050915
    p_fdat -> 20050811
    dias_v = 4
    try this and let me know.
    Message was edited by:
            Judith Jessie Selvi

  • How to add a date(Year, Month, Day) table in OBIEE Administrator

    Hi,
    I am new to this tool, we are developing a HR report for emp on leave or absentees. we have data since 1982 in our tables. we want to have a date table and dimension where we can give have a hierarchy for year, month, day, so that we can design our dashboards based on time. how we can do that in OBIEE Administrator and can we do it in warehouse builder as well, if so, how. ( we have a column for date in the table by name 'leave start date' and 'leave end date', can we use this and create our own table with year month and day as separate columns).
    Thanks.

    hi,
    Using date column u can create time dim in BMM layer
    Create a new logical table and pull your date column to this table
    Next,create following columns
    Refer http://www.rittmanmead.com/2007/04/30/obi-ee-time-dimensions-and-time-series-calculations
    leave start date
    Year level :Extract(year from date_column)
    Month and year level:CAST (Extract(month from fact_date_column) As CHAR(5) ) || CAST (Extract(yearfrom fact_date_column) As CHAR(5) )
    Mon-YYYY: EVALUATE('TO_CHAR(%1,%2)' AS CHARACTER ( 30 ), "Development".""."sample sales"."Dim - leave Date"."REPORT_DATE", 'MON-YY')
    YYYY-MM : CAST ( EXTRACT( YEAR FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") AS CHARACTER ( 4 )) || '/' || CASE WHEN EXTRACT( MONTH FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") BETWEEN 10 AND 12 THEN CAST ( EXTRACT( MONTH FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") AS CHARACTER ( 2 )) ELSE '0' || CAST ( EXTRACT( MONTH FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") AS CHARACTER ( 1 )) END
    Year Quater :: EVALUATE('TO_CHAR(%1,%2)' AS CHARACTER ( 6 ), "sample sales".""."sample"."Dim -Leave Date"."REPORT_DATE", 'YYYY') || '0' || EVALUATE('TO_CHAR(%1,%2)' AS CHARACTER ( 6 ), "sample sales".""."sample"."Dim -Leave Date"."REPORT_DATE", 'Q')
    Day: EXTRACT(DAY FROM DATE_COLUMN)
    Thanks,
    Saichand.v

  • Release Date for Albums Year, MONTH DAY

    Why can't I enter the release date for albums (Year month and day)?   Itunes has a field for year but that's it.    I would have loved to be at the meeting where it was discussed.
    "Year, month and day? why the heck would any want that?"
    "Well a lot of us want to see our albums in chronological order and you can't do that with just the year, many albums come out every year"
    "Blah Blah Blah, music is just to dance to, no one cares about dates, besides it would four extra digit fields in each entry"
    But seriously, I would think that Itunes would aspire to be THE program for music lovers.
    Instead of being able to just enter the release dates I have had to come up with my own work around.  I put a the release date in the format yyyymmdd in fromt of each title and then sort by titles.
    Now all of my Beatle albums finally show up in chronological order by release date.   But why should I have to massage the data like this.   I can't imagine what goes on at Itunes planning  sessions.  I'm very unhappy about the loss of cover flow but that's another story.

    I'm glad to hear that I am not the only one who sees this as a problem.  And another Beatles fan too.
    This is so fundamental.  Every album has a release date and it's part of the data that is always associated with  that album.   Why did Apple look at the data available for an album and consciously decide to truncate it?
    What kind of music lover isn't aware of when albums are released?  I just don't get it.
    I like having the date yyyymmdd in front of each album.   It isn't pretty but it means the albums are chronological.   If you want, you could just put this in the sort field and leave the regular album title in the regular field.   Then the names would be right and they would sort correctly.   But again.  Why should we have to do all that? 
    Apple is busy constantly changing where the controls are on I tunes  rather than fixing something simple and important like this.
    Today I wanted to load some songs onto my ipod touch and it took me 10 minutes to figure out how to sync because the last itunes update got rid of the side bar.  
    How are you supposed to get comfortable using a product when they keep moving the controls around?   Just quit apple.   leave the controls where they are.  Add new controls if needed but stop moving them.  I know I'm ranting now but I am honestly angry and frustrated,

  • Can I change the day/date format from US (month day year) to UK (date month year)?

    When I view databases through Firefox, the date/day format is set at month, day, year (US style), whereas I need day, month, year, I work in the UK and the "wrong" format is VERY confusing and could lead to errors/mistakes. IE has that format but I don't want to revert to using that.

    Gingerbread Man, thank you VERY much!! I followed your instructions and it works perfectly. I am a happy person :-))

  • Calculating years,months & days

    Hi,
    i have to calculate the time duration in years,months and days between contract_start_date and contract_end_date
    eg: Contract_Start_Date = '17-nov-2006' and Contract_End_Date = '21-jan-2008'

    Rehman wrote:
    Hi,
    i have to calculate the time duration in years,months and days between contract_start_date and contract_end_date
    eg: Contract_Start_Date = '17-nov-2006' and Contract_End_Date = '21-jan-2008'It's not the simplest of things to work out.
    If you use the intervals it will, like any other calculation, struggle with the fact that there are different number of days in the month and leap years to take account of.
    Whilst it's simple enough to determine how many whole years have passed and how many months difference there is, the moment you start to take account of the days you become stuck because days in conjunction with months cause the day calculation to be a little more indeterminate...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date,
      7         to_char(c_end_date,'YYYY')-to_char(c_start_date,'YYYY')
      8        -(case when to_date(to_char(c_end_date,'DD-MM')||'-1900','DD-MM-YYYY') <
      9                    to_date(to_char(c_start_date,'DD-MM')||'-1900','DD-MM-YYYY') then 1 else 0 end) as years_between
    10        ,case when to_date(to_char(c_end_date,'DD-MM')||'-1900','DD-MM-YYYY') <
    11                    to_date(to_char(c_start_date,'DD-MM')||'-1900','DD-MM-YYYY') then
    12                    12+(to_char(c_end_date,'MM')-to_char(c_start_date,'MM'))
    13         else (to_char(c_end_date,'MM')-to_char(c_start_date,'MM'))
    14         end -
    15        (case when to_date(to_char(c_end_date,'DD')||'-01-1900','DD-MM-YYYY') <
    16                   to_date(to_char(c_start_date,'DD')||'-01-1900','DD-MM-YYYY') then 1 else 0 end)
    17         as months_between
    18        ,case when to_date(to_char(c_end_date,'DD')||'-01-1900','DD-MM-YYYY') >
    19                   to_date(to_char(c_start_date,'DD')||'-01-1900','DD-MM-YYYY') then
    20              (to_char(c_end_date,'DD')-to_char(c_start_date,'DD'))
    21         else 31-(to_char(c_start_date,'DD')-to_char(c_end_date,'DD'))
    22         end as days_between_approx
    23        ,(c_end_date-c_start_date) year(4) to month as interval_yyyy_mm
    24* from t
    SQL> /
    C_START_D C_END_DAT YEARS_BETWEEN MONTHS_BETWEEN DAYS_BETWEEN_APPROX INTERVAL_YYYY_MM
    17-NOV-06 21-JAN-08             1              2                   4 +0001-02
    21-NOV-06 17-FEB-08             1              2                  27 +0001-03
    21-JUN-06 17-JUL-08             2              0                  27 +0002-01
    SQL>This example shows that a manual calculation can determine the number of years and months ok, but the days have to be approximated; and the interval answer isn't giving the same result for the months as the manual calculation because it can't take account of the days at the same time.

  • Add 1 day to the Month of February on leap year

    I know how to calculate leap year. The calculation is working great.
    However, I need to add a day to the month of February if a leap year is selected.
    Do you have any pointers on this?
    Thanks!

    Thanks!
    I got it
    if(leapYear){
    if (month==2)
    numDays = numDays +1;
    }

  • Year , Month & Day from Date.

    Hi HANA experts,
      Do help me to resolve this issue
    How can we extract or fetch year from the date.i went through some of the SCN blogs.where they create calculation views...but the steps are not that clear to me.
    can anyone please explain??
    My scenario is :
    I have date field in ANALYTIC VIEW which i have fetched from ECC  tables.
    now i need to get  the year  wise month wise and day wise reports. so what steps i should do in calculation view to get that??
    thanks
    Neeraja

    there is no ECC under SAP...as we are using suite on HANA fro AWS.and there is no restriction done by the basis till now...
    as we are new to these unable to trouble shoot things easily.
    thanks for your reply..

  • How to relate current day to date hierarchy [year - month - day] for SSRS report paramenter

    Hi there: 
      I've created a SSRS report based on OLAP cube. In this report, there is a date parameter which is used to filter out data. 
    Now , I want this report to be run and always retrieve data from previous day. I need to supply the date parameter with something
    like SQL syntax: DATEADD(dd,-1,GETDATE())  . The question is how can I do that in the MDX world? 
     thanks
     Hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Hi Hui,
    According to your description, you need to retrieve data from previous day, so you are looking for an expression in MDX which can achieve the requirement like SQL syntax: DATEADD(dd,-1,GETDATE()), right?
    As per my understanding, it easy to achieve this requirement in report level ranther than in MDX query level. You can create another hidden parameter "Date2" using the expression below.
    =DateAdd("d",-1,Parameters!Date.Value)
    Then use Date2 parameter to filter in the query.
    If don't want to create another parameter, you can use it like below.
    Year     =DatePart("yyyy",DateAdd("d",-1,Parameters!Date.Value))
    Quarter  =DatePart("qq",DateAdd("d",-1,Parameters!Date.Value))
    Month    =DatePart("mm",DateAdd("d",-1,Parameters!Date.Value))
    Week     =DatePart("ww",DateAdd("d",-1,Parameters!Date.Value))
    Besides, DateAdd function is supported in MDX, please refer to the link below.
    http://msdn.microsoft.com/en-us/library/hh510163.aspx
    If I have anything miunderstand, please point it out.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • Need to Display Data for Cummulated to Current Day of Current Fiscal Year

    We use fiscal variant V3 (April-March).  My need is to display data automatically from first of fiscal period (April 1 2006) to today.
    I tried using 0CYTCD on Calendar Day but this works only for the current calendar year that the system is in  i.e 2007.
    Is there a standard variable I can use on 0CALDAY so I always get data from day one of current fiscal year/period to today? e.g. April 1, 2006 to January 3, 2007
    If not, can someone please help with the exact customer exit code that I would need to write in CMOD in BW?
    Thanks a ton!

    I thought of using 0FYTCD variable, but I cannot find it in the business content.
    Has anyone used 0FYTCD (Fiscal year to current day) in BW 3.1 SP25?
    Again, I am looking for a variable that would get me the beginning of fiscal year to today.
    Thanks.

  • Hr Infotyp 552. FM - how to get the  Year Month Day?

    Hello
    In Infoty 552 you find a table with the dateelements  DURYY, DURMM, DURDD.
    But all field values are 0 when i look at the table with se16n.
    When i look at the infotyp with pa20, i see the right values - so they must be calculated at run time.
    Does anybody know a FM how to calculate these? i can't find them in debugger?
    thanks

    hi,
    You can use FM HR_READ_INFOTYPE for this purpose.
    HR_READ_INFOTYPE
    IMPORTING
         VALUE(TCLAS) TYPE  PSPAR-TCLAS DEFAULT 'A'
         VALUE(PERNR) TYPE  PRELP-PERNR ----------> Put perner
         VALUE(INFTY) TYPE  PRELP-INFTY     ----------> Turget infotype
         VALUE(BEGDA) TYPE  PRELP-BEGDA DEFAULT '18000101'
         VALUE(ENDDA) TYPE  PRELP-ENDDA DEFAULT '99991231'
         REFERENCE(BYPASS_BUFFER) TYPE  FLAG DEFAULT ' '
         REFERENCE(LEGACY_MODE) TYPE  BOOLE_D DEFAULT SPACE
      EXPORTING
         VALUE(SUBRC) TYPE  SY-SUBRC
      TABLES
          INFTY_TAB      -------------> internal table compatible to turget infotype
      EXCEPTIONS
          INFTY_NOT_FOUND
    Regards,
    Anirban

  • Convert two dates difference to number of years, months and days

    Post Author: gigimonu
    CA Forum: Formula
    I wanted to write a formula (if there is a function I can use) that can convert a date difference to total number of years, months and days example
    adate = 10/22/2006
    ?xdate = current date - adate (answer should be 1 years, 0 months and 0 days)
    Please help
    Thanks

    Post Author: V361
    CA Forum: Formula
    &#91;Years, Months, Days&#93;
    DATEVAR FROMDATE := DATE(2000,01,01); // FROM DATE
    DATEVAR TODATE := CURRENTDATE; // TO DATE
    NUMBERVAR YEARS;
    NUMBERVAR MONTHS;
    NUMBERVAR DAYS;
    STRINGVAR DIFF;
    DATEVAR TEMP;
    IF TODATE < FROMDATE THEN
    (TEMP := TODATE;
    TODATE := FROMDATE;
    FROMDATE := TEMP);
    YEARS := DATEDIFF('YYYY',FROMDATE,TODATE);
    IF YEARS > 2 THEN
    (YEARS := YEARS - 2;
    TEMP := DATE(DATEADD("M",YEARS * 12,FROMDATE));)
    ELSE
    (YEARS := 0;
    TEMP := FROMDATE);
    WHILE TRUE DO
    (TEMP := DATE(DATEADD('M',1,TEMP));
    IF TEMP > TODATE THEN
    EXIT WHILE;
    MONTHS := MONTHS + 1);
    DAYS := DATEDIFF('D',DATE(DATEADD('M',-1,TEMP)),TODATE);
    IF MONTHS > 12 THEN
    (YEARS := YEARS + INT(MONTHS/12);
    MONTHS := MONTHS MOD 12);
    DIFF := IIF(YEARS>0 ,TRIM(TOTEXT(YEARS,0)) & " YEARS " ,"0 YEARS ") &
    IIF(MONTHS>0,TRIM(TOTEXT(MONTHS,0))& " MONTHS ","0 MONTHS ")&
    IIF(DAYS>0 ,TRIM(TOTEXT(DAYS,0)) & " DAYS" ,"0 DAYS");

  • Difference between 2 dates in form of years,months and days.

    Hi friends,
      i need one function module for finding difference between 2 dates and the output is
    no. of years
    no.of months
    no. of days.
    it means the input is begin date and end date
    output is no.of years,no.of months and no.of days.
    for example begin date is today i.e., 08/02/2008 (dd/mm/yyyy) and end date is 07/03/2008 then the output is
    no.of years -
      0,
    no.of months----
      1,
    no.of days----
      0.
    and one more example if begin date 08/02/2008
    (dd/mm/yyyy) and end date is 01/02/2008 then the output is
    no.of years -
    0,
    no.of months----
      0,
    no.of days----
    -7..
    Please help me it's very urgent

    Hi,
    Use FM HR_AUPBS_MONTH_DAY.
    It Calculate the years, months, days & cal days between 2 dates.
    Hi,
    The FM is 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    Check the following example:
    DATA: EDAYS LIKE VTBBEWE-ATAGE,
    EMONTHS LIKE VTBBEWE-ATAGE,
    EYEARS LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
    TODATE LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    exporting
    i_date_from = FROMDATE
    i_date_to = TODATE
    I_FLG_SEPARATE = ' '
    IMPORTING
    E_DAYS = EDAYS
    E_MONTHS = EMONTHS
    E_YEARS = EYEARS.
    WRITE:/ 'Difference in Days ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.
    Also You can write your own function module for this..
    just extract day and month and year from the two dates and then get the difference.
    suppose date 1 - y1m1d1
    date 2 = y2m2d2
    data : y1(2) type n,
    m1(2) type n,
    d1(2) type n,
    y2(2) type n,
    m2(2) type n,
    d2(2) type n,
    y1 = date1(4).
    m1 = date1+4(2).
    d1 = date1+6(2).
    y2 = date2(4).
    m2 = date2+4(2).
    d2 = date2+6(2).
    then get the differnce between years and days and months and store them in ur variables
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • How to do a date validation with leap years

    I'm doing a date validation program in my Java class, and well it's pretty hard (for me that is). I have to be able to type in a date, have it say whether it's a leap year or not, and print out the number of days in the month. It seems pretty straight forward, but I get confused on trying to do the 'if else' statements and even the simplest things like getting the day prompting to work. >< The years I'm doing only goes through 1000 to 1999, so that's why those numbers are there. The program isn't complete, so if anyone could help show me what I'm doing wrong in the areas I'm working on then I'd appreciate it...and I'm still kind of in the basics of Java so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced so yea.
    // Dates.java
    // Determine whether a 2nd-millenium date entered by the user
    // is valid
    import java.util.Scanner;
    public class Dates
    public static void main(String[] args)
    int month, day, year; //date read in from user
    int daysInMonth; //number of days in month read in
    boolean monthValid, yearValid, dayValid; //true if input from user is valid
    boolean leapYear; //true if user's year is a leap year
    Scanner scan = new Scanner(System.in);
    //Get integer month, day, and year from user
    System.out.print("Type in the month: " );
              month = scan.nextInt();
    System.out.print("Type in the day: " );
              day = scan.nextInt();
    System.out.print("Type in the year: " );
              year = scan.nextInt();
    //Check to see if month is valid
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;
    //Check to see if year is valid
    if (year >= 1000)
    year = year;
    else
    if (year <= 1999)
    year = year;
    else;
    //Determine whether it's a leap year
    //Determine number of days in month
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
         System.out.println (Number of days in month is 31);
         else (year == 4 || 6 || 9 || 11)
         System.out.println (Number of days in month is 30);
    //User number of days in month to check to see if day is valid
    //Determine whether date is valid and print appropriate message
    // Dates.java
    // Determine whether a 2nd-millenium date entered by the user
    // is valid
    import java.util.Scanner;
    public class Dates
    public static void main(String[] args)
    int month, day, year; //date read in from user
    int daysInMonth; //number of days in month read in
    boolean monthValid, yearValid, dayValid; //true if input from user is valid
    boolean leapYear; //true if user's year is a leap year
    Scanner scan = new Scanner(System.in);
    //Get integer month, day, and year from user
    System.out.print("Type in the month: " );
              month = scan.nextInt();
    System.out.print("Type in the day: " );
              day = scan.nextInt();
    System.out.print("Type in the year: " );
              year = scan.nextInt();
    //Check to see if month is valid
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;
    //Check to see if year is valid
    if (year >= 1000)
    year = year;
    else
    if (year <= 1999)
    year = year;
    else;
    //Determine whether it's a leap year
    //Determine number of days in month
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
         System.out.println (Number of days in month is 31);
         else (year == 4 || 6 || 9 || 11)
         System.out.println (Number of days in month is 30);
    //User number of days in month to check to see if day is valid
    //Determine whether date is valid and print appropriate message
    }

    Here are some helpfull hints for you:
    1. Your code is really hard to read, there are two main reasons for this. First, your indentation sucks. Second, you seem to be fascinated with saving two (ok four if you count the shift key) keypresses to avoid using { and }.
    2. Not using the brackets (you know { and } which you like to avoid) also is causing your code to do some stuff you don't realize or want to happen, or at least it would be if your code compiled.
    3. If statements require arguements, "year == 1" is an arguement, "3" is not an arguement. Each operator like the or operator ("||") is essentially a new if and requires a complete arguement. So the following code peice:
    if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)Literally translates to if year equals 1 or if 3 or if 5 or if 7 or if 8 or if 10 or if 12. Doesn't make much sense in english, and it doesn't make much sense in Java either.
    4. I am pretty sure "year" is not the variable you want in the code snippet above (the one used in hint 3), especially considering years 1, 3, 5, 7, 8, 10, and 12 are not between 1000 and 1999. You need to be really carefull not make these kind of mistakes when coding, because they are by far the hardest to track down and fix later since they don't really throw up any flags or anything at compile or run time. Take your time and think thuroughly about each line of code while coding it, it will save you tons of time in the long run.
    5. What exactly do you expect statements like "month = month;" to do? That translates as make month equal to month. Do you go to the bank and say " I have exactly $3.56 in my pocket, so I would like to deposite all $3.56 and then withdraw $3.56 and put it back in my pocket"? How do you think the teller would look at you? Teller would probably do it, but the teller would feel like he/she wasted time with you and that you are not really right in the head. Java feels the same way when you make it do the same thing, and you love to do it.
    6. Code like the following is all wrong, and for more reasons than pointed out in hint 5.
    if (month >= 1)
    month = month;
    else
    if (month <= 12)
    month = month;
    else;Let's say someone put 13 in as the month. It passes the first check because 13 is greater than or equal to 1. so month which is 13, now gets set to 13 (gee that was effective). Now we hit the else and things get confusing because you didn't use brackets or proper indentation (hint 1) so we don't know what your real intent was. Did you mean else do nothing, and the next if statement is then executed, or did you mean to just run the next if statement if the else condition was met? Fortunatly it doesn't matter here because the next if statement is failed anyways since 13 is not less than or equal to 12.
    So, we leave this code with month ebing 13, wait when did we add a 13th month to the calendar? Are you using the Jewish calendar? Could be, except even if I put 1234567 as the month your code would except it as valid, and I know no calendar with that many months. Try writing this in english first and translating it to jave, like i would probably say "if the month is greater than or equal to 1 and less than or equal to 12 then the month is valid." Course now what do you do if it is invalid? Hmm, maybe I would actually say "while the month is less than 1 or greater than 12 ask the user for the month" until they get it right.
    There are a few other problems, but most of them are probably things you haven't learned yet, and they are not show stoppers so we will let them fly. You already have a lot of work to do to make this better. But I do have one more really really big usefull hint for you:
    Never, ever, under any circumstances, should you ever ask in any way or even hint at asking for someone else to provide code solutions to your problems. So "so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced " was a very bad thing to do, but fortunatly for you you followed it with proof you were trying to write the code yourself. Had the code you provided not been so full of problems it was obvious a beginner wrote it, you would probably have gotten much less cordial responses. I would seriously consider avoiding any implication of wanting code, at least until you become a regular poster here and people know you are not just looking to get your homework done for you.
    Hope some of this helps.
    JSG

Maybe you are looking for

  • Opening a file in Crystal Reports

    Hello.  When I try to open a file in Crystal Reports it gives me an error message "the parameter is incorrect".  Please advise.  Thanks. Cindy

  • Link b/w QALS and MSEG TABLE

    hi, i want to make a link up between QALS AND MSEG table as i want to those inspection lot which have the UD = REJECTED and stored in SC01 etc storage locations. Till now i am able to find that the Item which are rejected having material documents pr

  • How do I get podcasts on my 3g iPod?

    I'm up to date on all my software, but I can't seem to bring up my podcasts on my 3g iPod. Although others have experienced this problem, a few others bring up podcasts without any difficulty. I have lots of podcasts, definitely want them to appear i

  • Dev Webdynpros/BSPS on WAS640 for a R/3 46c backend.

    Hi, As mentioned, either a webdynpro or a BSP application needs to be developed on WAS 640 for an R/3 46C residing in the backend. The problem: We need to access a transaction (VA21 in SD R/3 4.6C)over WebDynpro/BSP. I have earlier come across access

  • Question On Sun Grid Engine

    Hi, May i know how can i submit a job to the the sun grid engine for processing?