Checking for a valid date

I have a program that takes a user's input from three text boxes to make a date. I need to be able to check to make sure that the day of the month is correct. For example if they enter 02/35/02 an error message should apear. I am trying to use a Calendar object to do this with but it isn't working. Here is my code:
                String strMonth = month.getText();
          int intMonth = Integer.parseInt(strMonth);
          if ( (intMonth < 1) || (intMonth > 12) ) {
               invalidDate("month",month.getText());
               month.requestFocus();
               return;
          else if(strMonth.length() == 1) {
               strMonth = "0" + strMonth;
          //Formating the year
          String strYear = year.getText();
          int intYear = Integer.parseInt(strYear);
          if (strYear.length() == 1) {
               //User entered only one digit
               strYear = "200" + strYear;
          else if(intYear > 40) {
               //User entered a year greater than 40 so must be 19??
               strYear = "19" + strYear;
          else {
               //If neither of the above then must be 20??
               strYear = "20" + strYear;
          intYear = Integer.parseInt(strYear);
//-----------RIGHT HERE IS MY PROBLEM------------------------------          
          //Check the day field using the month and year
          String strDay = day.getText();
          int intDay = Integer.parseInt(strDay);
          Calendar cal = Calendar.getInstance();
          cal.clear();
          cal.set(Calendar.MONTH,intMonth);
          cal.set(Calendar.YEAR,intYear);
          cal.set(Calendar.DAY_OF_MONTH,intDay);
          int min = cal.getMinimum(Calendar.DATE);
          System.out.println("Min Day: " + min);
//-------------The variable max is always 31----------------------          
                int max = cal.getActualMaximum(Calendar.DATE);
          System.out.println("Max Day: " + max);
          if( (intDay < min) || (intDay > max) ) {
               //User entered an invalid date
               invalidDate("day",strDay);
               day.requestFocus();
               return;
          else {
               //User entered a valid date
               if(strDay.length() == 1) {
                    strDay = "0" + strDay;
          //Everything is correct
          requestedDate = strMonth + "/" + strDay + "/" + strYear;
          System.out.println("All correct: " + requestedDate);The problem is that when I do this the variable max that I use to get the maximum day in the month is always 31. I would appreciate any help.

import java.util.*;
import java.text.SimpleDateFormat;
public class Test {
  public static void main(String args[]) {
    GregorianCalendar c = new GregorianCalendar();
    c.set(Calendar.MONTH, 9);
    c.set(Calendar.YEAR, 2002);
    c.set(Calendar.DATE, 40);
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    System.out.println("Date is "+sdf.format(c.getTime()));
    GregorianCalendar tmp = new GregorianCalendar();
    tmp.setTime(c.getTime());
    tmp.add(Calendar.MONTH, 1);
    tmp.set(Calendar.DATE, 1);
    tmp.add(Calendar.DATE, -1);
    System.out.println("Days="+tmp.get(Calendar.DATE));
}

Similar Messages

  • Oracle Error occured, while checking for Already Committed data

    Hi,
    In my 1 day old workspace I see more than 3000 errors logged in the owb_error_log_table with text as shown below , can someone from Oracle please advise what the problem seems to be ?
    Oracle Error occured, while checking for Already Committed data : 76291.DBObject.TABLE_1.2.en_GB
    Oracle Error occured, while checking for Already Committed data : 76291.DBObject.TABLE_1.1.en_GB
    Oracle Error occured, while checking for Already Committed data : 42483.PlatformConfiguration.ORACLE.1.en_GB
    Oracle Error occured, while checking for Already Committed data : 42483.PlatformConfiguration.ORACLE.2.en_GB
    There are many more examples of other errors as well. Google returns nothing for these error....am I the first one to face these errors. We are using 11gRelease2 on RHEL.
    They all have a error text of ORA-01403: no data found
    tks in advance.

    I haven't been able to pin it down to a specific action that causes these errors. I have been having various other problems when importing tables ...the screen just freezes and nothing happens. When I queried this table from sql developer to check if I can spot anything and I found these errors.
    The screen freezes when I add a new oracle location - the test works fine - but when I click OK to the add oracle location screen it just freezes and nothing happens.

  • Global automatic check for "process valid after_YYYYMMDD" available?

    Hi, I want to attach the info that a process is only valid after a specific date. Each time a process-instance will be created it has to be checked if the actual date is higher than the date specified and only then the process-instance can be created.
    Is there a way to define a automatic global check of the validity of each process?
    Thanks, Soja.
    PS: I could simply define an additional variable in the deployment descriptor but that would require that each process has to check in it's first activity the actual date and the validity-date of the process.

    thanks for the reply . i have found the way to push the command to client using intune but the issue is with the command its not working.
    %programfiles%\Microsoft\OnlineManagement\Updates\Bin\omupdclt.exe /detectnow
    · %programfiles%\Microsoft\OnlineManagement\Updates\Bin\omupdclt.exe /updatenow
    These commands are not getting executed at the client machine.i tried it's execution in administrator mode.Command is  getting executed without any error but check for update is not getting initiated .
    can u please provide me with the way to execute this manually at the client machine. 
    thanks 
    Mayank Pahan

  • Authorization check for Vendor Master Data

    Hi,
    I have a requirement where I want to restrict some of the end users in viewing accounting data of vendors. In XK02/XK03 there is a sub screen for Company code data (Accounting info/Payment trans./with holding tax). I want to put a check for the selection of these check-box. System should allow some of the users to view these data. I tried for exit/BAdis , but didn't find anything as per my requirement. Please give some suggestions.
    Thanks & Regards
    DR

    Hi
    Check BADI ADDRESS_SUBSCREEN, I think you can implement this one and add a authority check here.
    check the method ADDR_APPL_SUB_PAI_IMPORT
    Regards,
    Himanshu

  • Jquery to check for overlapping of dates

    Hi All,
    I have a conference room booking calendar on moss 2007 site. i want to check for overlapping date i.e. no body should book the conference room for a time period which has already been booked by some one else. I need to include a jquery code on the web part.
    Kindly help me on the same.

    Hi,
    I think this is possible if you have the necessary datetime fields and if you incorporate some Javascripts:
    http://spjsblog.com/2012/02/25/spjs-resource-management-no-more-double-booking/
    With some server side code (which I believe could also be replaced by client javascript code):
    http://aleemsheikh.wordpress.com/2011/08/08/warn-users-of-double-booking-in-sharepoint-calendar-in-real-time/
    Alternative would be either an Event Receiver or a workflow:
    https://www.nothingbutsharepoint.com/sites/eusp/Pages/SharePoint-Double-Booking-with-the-Calendar.aspx
    http://sharepoint.stackexchange.com/questions/18086/calendar-items-at-same-time

  • User Exit for VA41 Validity Date

    Hi,
    I am giving order type in VA41 Tcode and then Clicking on 'Create with Reference' .Then a Pop Up is getting generated. In this i am giving Contract created with validity date lessthan today's date(in Contract Tab).For Example i created a Contract xxxxxx with 'valid to' 9.12.2008. When I am giving this contract and clicking on 'Copy' button a Warning message is getting generated 'The sales document is only valid until 09.12.2008'. Now i have to change this into Error message instead of Warning Message.
    i used User Exits mv45afzz,MV45AFZA,MV45AFZB. But the debugger is getting started only after Warning message got generated.Is there any User Exit for which debugger gets started when i give the Contract and then Click on 'Copy' button. Please Suggest.
    Thanks
    K Srinivas

    Hi,
    Create a file say breakpoint.txt file as follows:-
    [FUNCTION]
    Command=/H
    Title=Debugger
    Type=SystemCommand
    Once you come to the screen of 'Create with reference' where you are giving the contract, from  second session drag the above mentiuoned file to the session where you are running VA41, & drop it here. Now debugger has been activated. Proceed with debugging. This method you can use for any of the 'POP UPs'.
    I hope this helps,
    Regards
    Raju Chitale

  • Check for URL validity

    Ive done a quick google, and there are several methods by which to do this, but seem to tend towards http URLS.
    Essentially i just need to check if an ftp address is valid. i.e. There is a server there that responds in some fashion.
    Connection isnt necessary.
    Thanks

    JamesBarnes wrote:
    Essentially i just need to check if an ftp address is valid. i.e. There is a server there that responds in some fashion.
    Connection isnt necessary.Yes, it is. The only way to tell if there's an ftp server responding at some address and port is to connect to it.
    It's generally pointless to do these kinds of tests. If the URL class provides validation of the format, take what you can get there to see if it at least could be legal vs. is clearly totally bogus, but other than that, just try to connect. If you can, it's valid. If you can't, then either the server is not running or there's no network path to it. Diagnosing that is outside the scope of your application. (Unless you're writing a network services monitoring/management tool.)
    Even if you had some separate test and it succeeded, between the time that test passes and you try to connect, the server could shut down or a network problem could develop, so you cannot assume that just because the test passes, you can connect. Your connection and usage code will still have to handle communication failures.

  • Check for Failed Validation

    Hi,
    Is there any value in session or any where else, that can be checked to see if ANY validation has failed?
    I have a report flag that needs to be reset if ANT validation has failed, so that the report will not continue to run.
    Thanks,
    Keisha

    Take a look at apex_application.g_inline_validation_error_cnt
    http://www.talkapex.com/2010/06/conditional-validations-in-apex.html

  • How to extends JSpinner to check for input validation.

    I have JSpinner instantiated with a SpinnerNumberModel. If I enter a number for example 123 I am happy with it. However if enter 12a3, I would like the spinner to the notify the user of the error, instead of parsing the number to just 12.
    Thank you.

    The text component of a JSpinner that uses numbers is a called a NumberEditor and is an inner class of JSpinner. You can read the API here
    It uses a JFormattedTextField to accept input, and you would do well to read the API on this as well. You may need to substitute a plain JTextField with a DocumentListener, but I haven't tried this so can't fully vouch for this.
    oh, and as always, please simply ignore alexxzius.
    Edited by: Encephalopathic on Jul 4, 2008 11:25 AM

  • Field Level Validation - Date Mask

    Hi all
    I need some Java Script to validate a date mask in a field. Format must be:
    dd-mm-ccyy.
    Can anyone help me?
    Thanks

    Here is a copy of the script I set up to do validation.
    I not only wanted it to check for a valid date,
    but I wanted to store leading zeros, but not make the user type them in.
    One of the things you have to do is to set the format mask for the date to MM-DD-YYYY for each date field in your form.
    Here it is:
    var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    var MonthArray =new Array("01","02","03","04","05","06","07","08","09","10","11","12");
    var firstDash = null;
    var lastDash = null;
    var inYear = null;
    var inMon = null;
    var inDay = null;
    var today = new Date();
    var curFullYear = today.getFullYear();
    var strYear = String(curFullYear);
    var thisCentury = strYear.slice(0,2);
    var thisYear = strYear.slice(2);
    var numThisYear = Number(thisYear);
    inDate = theElement.value;
    if (inDate.length == 0) return true;
    /* Check for a valid format. */
    var filter=/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{2,4}$/;
    if (! filter.test(inDate))
    { alert("Please enter date in MM-DD-YY or MM-DD-YYYY format.");
    theElement.focus();
    theElement.select();
    return false;
    /* Pick off the indices (zero-based) of the two dashes. */
    firstDash = inDate.indexOf("-");
    lastDash = inDate.lastIndexOf("-");
    if ((firstDash == lastDash) &#0124; &#0124; (firstDash == -1) &#0124; &#0124; (lastDash == -1))
    alert("Please enter date using dashes (-), e.g. MM-DD-YY or MM-DD-YYYY.");
    theElement.focus();
    theElement.select();
    return false;
    /* Pick off the month and day (pad with leading zero, if necessary). */
    inMonth = inDate.slice(0,firstDash);
    if (inMonth.length == 1) inMonth = "0" + inMonth;
    inDay = inDate.slice(firstDash+1,lastDash);
    if (inDay.length == 1) inDay = "0" + inDay;
    /* Pick off the year. Filter ensures 2, 3, or 4 digit year. 4 is what we */
    /* want, so we only have to deal with 2 or 3 digit years. */
    inYear = inDate.slice(lastDash+1);
    /* If the user entered a two digit year, figure out which century to pad. */
    if (inYear.length == 2)
    /* Adding 5 years is still within the current century... */
    if ((numThisYear + 5) < 100)
    /* 00 to (current year + 5 years) should use the current */
    /* century; otherwise, use the previous century. */
    if (inYear > (numThisYear + 5))
    inYear = (thisCentury - 1) + inYear;
    else
    inYear = thisCentury + inYear;
    else
    /* Adding 5 years would rollover the century, use the current century */
    inYear = thisCentury + inYear;
    /* A 3 digit year is an error. */
    if (inYear.length == 3)
    alert("Please enter date with either a 2 digit or 4 digit year.");
    theElement.focus();
    theElement.select();
    return false;
    /* Check for a valid month. */
    var filter=/01|02|03|04|05|06|07|08|09|10|11|12/;
    if (! filter.test(inMonth))
    alert("Please enter a valid month.");
    theElement.focus();
    theElement.select();
    return false;
    /* Check for leap year. */
    N=Number(inYear);
    if ( ( N%4==0 && N%100 !=0 ) &#0124; &#0124; ( N%400==0 ) )
    DayArray[1]=29;
    /* Check for valid days for the month. */
    for(var ctr=0; ctr<=11; ctr++)
    if (MonthArray[ctr]==inMonth)
    if (inDay > DayArray[ctr] &#0124; &#0124; inDay <= 0)
    alert("Please enter a valid day.");
    theElement.focus();
    theElement.select();
    return false;
    /* Output the fixed up date. */
    theElement.value = inMonth + "-" + inDay + "-" + inYear;
    return true;
    Regards,
    Rene'

  • LabVIEW DSC 8.0 examples that deal with events check for valid timestamp.Why?

    Hi folks !
    There are examples that come with LabVIEW DSC 8.0 that deal with alarm events, In these examples - DSC Alarms Event Structure Support.vi contained in DSC Alarms Demo.lvproj, for instance - when an alarm event occurs, the code checks for a valid time stamp - 17:00:00.000 31/12/1975. I´m confused, can anyone help me understanding why it´s done?
    Thanks !

    Hello marc8470,
    Each Virtex 5 FPGA bank requires an external voltage reference.  The FlexRIO FPGA module provides this reference in the form of Vccoa and Vccob.  Because there are two voltage references available on the FlexRIO FPGA module, each Vcco reference is connected to 2 IO banks.  The Adapter Module Interface and Protocol chapter of the FlexRIO MDK manual has a table that indicates which GPIO banks are referenced to which Vcco reference.  The Vcco levels set in the general section of the adapter module configuration file are not used by the Xilinx compiler, but instead by the fixed FlexRIO logic to configure the external voltage references.  The IO standard constraints section of the adapter module configuration file is used during compile to configure the output drivers in the Virtex 5.  If the general VccoALevel and VccoBLevel values do not match the IO standard constraints, no error will occur during compile, but the hardware will not be configured correctly during runtime.  The logic families used by each general purpose IO (GPIO) line must match that of the Vcco levels set in the general section of the adapter module configuration file.  A mismatch in values could result to incorrect behavior or possible damage to the FlexRIO FPGA module or the adapter module. 
    In the future, please use the email address included in your NI FlexRIO Adapter Module Development Kit (MDK) User Manual to send your questions directly to the FlexRIO MDK support team.  This group has experience with specific FlexRIO MDK questions such as this one. 
    The FlexRIO MDK manual is designed to provide all of the information a hardware designer will need to create a FlexRIO adapter module.  National Instruments is always improving and working on new releases of the FlexRIO MDK.  Please feel free to use the support email address in the FlexRIO MDK manual to send me any feedback you have on the contents of the manual.
    Regards,
    Browning G
    FlexRIO R&D

  • Same deliveries for different delivery dates on Po

    I have a requirement
    If we use standard SAP and have a purchase order with materials that have different planned delivery times, we are going to create multiple deliviers from the PO based upoon the delivery creation date calculation.   Since we want to ship all of these materials on the same delivery ,  we have an issue.
    Is there any workaround for this ? PL help me.
    Thanks.

    Hi,
    If you have a different delivery schedules for a material with the vendor you can go for Scheduling agreement which is good option for this.
    Because in PO if you maintain the delivery schedules in Item detail>Delivery schedule  there is no check for this delivery dates.You can inward all the stock in a single delivery which don't have a control on that dates.
    If you follow the Scheduling agreement then system will not allow you to post the stock unless the delivery date is valid.
    rgds
    Chidanand

  • Find the 'DAY' for a given 'DATE'

    Hi Folks,
    I need a help regarding finding the day for a given date.
    My requirement is that..,
             If I enter a date using 'parameters', it should write the 'day' for the corresponding date.
    To be more specific.....,
    if I enter date as ' 07/15/2008 ' it should return me  the day as 'Tuesday'.
    Regards,
    Naveen G

    HI,
    FM LIST WITH RESPECT TO DAY, WEEK, AND MONTH.
    CALCULATE_DATE : Calculates the future date based on the input .
    DATE_TO_DAY : Returns the Day for the entered date.
    DATE_COMPUTE_DAY : Returns weekday for a date
    DATE_GET_WEEK : Returns week for a date
    RP_CALC_DATE_IN_INTERVAL : Add days / months to a date
    MONTHS_BETWEEN_TWO_DATES : To get the number of months between the two dates.
    END_OF_MONTH_DETERMINE_2 : Determines the End of a Month.
    HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.
    FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.
    MONTH_NAMES_GET : Get the names of the month
    WEEK_GET_FIRST_DAY : Get the first day of the week
    HRGPBS_HESA_DATE_FORMAT : Format the date in dd/mm/yyyy format
    SD_CALC_DURATION_FROM_DATETIME : Find the difference between two date/time and report the difference in hours
    L_MC_TIME_DIFFERENCE : Find the time difference between two date/time
    HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months
    LAST_DAY_OF_MONTHS : Returns the last day of the month
    DATE_CHECK_PLAUSIBILITY :Check for the invalid date.
    Reward points if useful,
    siri

  • Rule Builder Validity Date error

    I've created territories with validity dates, rule policy, ect.  When I start entering rules, no matter which territory I select, I get the following Consistency Check error.
    Validity dates of rule TN Territories should lie with in the selected validity 00/00/0000-00/00/0000.
    The rules are within the validity dates of the territories but those validity dates don't seem to be picking up in the rule builder.  Anyone have any ideas????

    Dear Seguin,
    I have the same problem at one of my customers system. I was glad to see your thread.
    Could you please give me more details how you solved this issue.
    Thank you and best regards
    Stefanie

  • Can I exit from paintComponent?  ...or... how can I check for invalid data?

    I'm writing a calendar applet for a programming class and I've nearly completed it but I'm stuck at checking for valid data.
    What seems to be happening is that paintComponent() is being called before actionPerformed.
    In actionPerformed (when they click the button), it checks to make sure they entered a valid month (1 to 12). If the didn't it dispalys a message, but if they did it calls repaint().
    But even if repaint() isn't called, Java still seems to call it before actionPerformed and I get exceptions.
    So I tried checking inside of paintComponent() by using a simple if(...) return; but that doesn't seem to do anything... it just keeps going through with the method.
    So -- Once the user presses my button I want to make sure the data is valid before repainting the screen. How can I do this?

    I validate it in actionPerformed which is called by
    the action listener... that is what you meant right?
    The problem is that it seems paintComponent() is being
    called before I can validate the data with
    actionPerformed(). I need to stop paintComponent()
    from always being calledMVC. (Model, View, Controller)
    Initially the internal value of the data (the model) should be valid (or null with a check in the paintComponent method)
    paintComponent (the view part) shows the state of the valid data.
    You press the button.
    actionPerformed is called (the controller).
    It checks the value and, if valid, writes it to the data (model), then updates the view.
    At no point will the view have to render invalid data, because the model is only updated after actionPerformed checks the value.
    The pattern may be applied with different classes performing the three roles, or different methods in the same class (sometimes it's easier that way for simple cases).
    Pete

Maybe you are looking for

  • Information, bookmarks, links, etc. won't delete...

    Macbook not updating information in bookmarks, dock, and dashboard - if I delete old links, it comes back each time. Programs reappear in the Dock, notes reappear in the dashboard, and bookmarks come back in Safari. anyone have ideas?

  • Data type could be same base on source table for blank column

    We have an employee table as mentioned structure. EMPNO NUMBER(4), ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2) I want to create a view base on the same/exact structure data ty

  • I cant update my Itunes to 10.5 on windows vista.

    Does Any Body Know What To Do With This? How I Can Fix It To Update My I-Tunes? Thanksss Guys x

  • ARD 3.5.1 DNS NAMES

    Hi, All imacs run 3.5.1 and i'm seeing a lot of inconsistency in the DNS Name column. Here are some examples: hostname.local hostname.domain.com and quite a few still have the dns name of the master image that was applied to the machine. The computer

  • Strge issue with reports

    Hi, I have 852's being enqueud once in a week and the size of the document the document is huge about 5MB to 10 MB. Generally, when ever this enqueue happens I see the report of it in B2B as the data which is enqueued in AQ is picked up by B2B and pr