Validate date using RE

Hey guys,
Need to validate date using RE in format MM/DD/YYYY and optional HH:MM:SS
I already have simple solution, but would like to add checks for leap year and dates like 02/30/2006 or 04/31/2006
So far I have this:
private static final String datePattern =
     "^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d" +
     "(\\s(([0-1]?[0-9]|2[0-3]):([0-5]?[0-9]):([0-5]?[0-9]))){0,1}$";

A much better way is to specify the format of the data and parse it using the SimpleDateFormat class method parse.

Similar Messages

  • How to validate date using case statement.

    I have date like 022212. I split month,date,year using STUFF Function. Now, i have to validate month in range 01-12 and date in range 01-31.  Can some one help me with the query.
    Thanks, Shyam Reddy.

    That is not  date; it is apparently a string (we have no DDL because you are so rude). Any competent SQL programmer will use DATE.   You want help with a query, but there is no query.  
    CAST ('20' + SUBSTRING (crap_string_date, 5,2)+'-' + SUBSTRING (crap_string_date, 1,2) + '-' +  SUBSTRING (crap_string_date, 3,2)  AS DATE) AS redddy_screwed_up_date 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Validate data Using Table maintence generator

    Hi Gurus,
    I need to validate a first 2 char of a field(say fld1-char 3) of a table(say TAB1) against a field (say fld2 -char 2) of another table Tab2.
    In the maintence screen PAI ,I am using 'Field & Select' keyword to validate the fld1 against fld2.
    Code:
    FIELD ZZMAL_HR-DAT00 SELECT   *
                FROM  t548y
                WHERE datar = ZZMAL_HR-dat00+0(2)
                INTO  DAT00
                WHENEVER NOT FOUND SEND ERRORMESSAGE 001.
    But on data insertion screen :
    a) on directly entering invalid value to the screen field & pressing save button,it saves it.
    b)on taking F4 prompt & selecting the value,it is not copied to the screen field.
    Can any body explain how to solve it?
    if I am directly hard coding like:
    field ZZMAL_HR-DAT00 values ('Z1','Z2','Z3','Z4').
    this works fine!
    All the code is written in PAI directly.
    Since I am not able to create module(unavailability of acess key),i am not able to even use hard coded break points(it becomes  a syntax-error) & also call to 'F4- ..' fn etc can not be made in POV, as Call keyword  is only allowed in PAI & PBO!(when coding directly in Flow logic without any module).......
    Awaiting guidance........
    regards,
    Gaurav

    Before you hit the SAVE button, have you tried putting /h in the command box and hitting ENTER to invoke the debugger?  It may be somewhat difficult to work through the SAP generated code.  Try and determine if your code is getting executed.
    I also see from the documentation on this feature, that the syntax restrictions for SELECT are different from SELECT in ABAP code.  Try coding
    datar = ZZMAL_HR-dat00
    without the offset info and see if that makes a difference.  Also try leaving out the INTO clause since you do not really need the data.

  • What is the best approach/tools/methodolgy to validate data in SSIS

    Hi,
    I have implemented ETL packages for more than 200 tables . I logged the row count as a first step for testing. Now i would like to implement automation/validate data using test cases.
    Being a single resource to do all this process is little difficult for the give time frame:(
    Could you please guide me for effective testing scenarios(automation technique) with optimum effort?

    I have a script that among all other things does
    dtexec.exe package_name /Validate
    Other than that, there is a grater danger down the road from schema changes.
    Arthur My Blog

  • How can I validate a date using sql

    How can I validate a date using sql or pl/sql
    select to_date('01/01/2009','mm/dd/yyyy') from dual this is a good date
    but how can I check for a bad date
    select to_date('0a/01/2009','mm/dd/yyyy') from dual
    Howard

    William Robertson wrote:
    It'll be complicated in pure SQL, as you'll have to parse out day, month and year and then validate the day against the month and year bearing in mind the rules for leap years. It would be simpler to write a PL/SQL function and call that.Nah, not that complicated, you just need to generate a calender to validate against.
    SQL> ed
    Wrote file afiedt.buf
      1  with yrs as (select rownum-1 as yr from dual connect by rownum <= 100)
      2      ,mnth as (select rownum as mn, case when rownum in (4,6,9,11) then 30
      3                            when rownum = 2 then 28
      4                       else 31
      5                       end as dy
      6                from dual
      7                connect by rownum <= 12)
      8      ,cent as (select (rownum-1) as cen from dual connect by rownum <= 21)
      9      ,cal as (select cen, yr, mn,
    10                      case when ((yr = 0 and mod(cen,400) = 0)
    11                             or (mod(yr,4) = 0 and yr > 0))
    12                            and mn = 2 then dy+1
    13                      else dy
    14                      end as dy
    15               from cent, yrs, mnth)
    16  --
    17      ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    18  --
    19  select case when cal.cen is null then 'Invalid Date'
    20              when not regexp_like(dt,'^[0-9]{1,2}[\/.-_][0-9]{1,2}[\/.-_][0-9]{4}$') then 'Invalid Date'
    21         else dt
    22         end as dt
    23  from dt left outer join
    24               cal on (to_number(regexp_substr(dt,'[0-9]+')) between 1 and cal.dy
    25                   and to_number(regexp_substr(dt,'[0-9]+',1,2)) = cal.mn
    26                   and floor(to_number(regexp_substr(dt,'[0-9]+',1,3))/100) = cal.cen
    27*                  and to_number(substr(regexp_substr(dt,'[0-9]+',1,3),-2)) = cal.yr)
    SQL> /
    Enter value for date_dd_mm_yyyy: a1/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select 'a1/02/2008' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 01/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '01/02/2008' as dt from dual)
    DT
    01/02/2008
    SQL> /
    Enter value for date_dd_mm_yyyy: 29/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '29/02/2008' as dt from dual)
    DT
    29/02/2008
    SQL> /
    Enter value for date_dd_mm_yyyy: 30/02/2008
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '30/02/2008' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 29/02/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '29/02/2009' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 28/02/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '28/02/2009' as dt from dual)
    DT
    28/02/2009
    SQL> /
    Enter value for date_dd_mm_yyyy: 0a/01/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '0a/01/2009' as dt from dual)
    DT
    Invalid Date
    SQL> /
    Enter value for date_dd_mm_yyyy: 00/01/2009
    old  17:     ,dt as (select '&date_dd_mm_yyyy' as dt from dual)
    new  17:     ,dt as (select '00/01/2009' as dt from dual)
    DT
    Invalid Date
    SQL>

  • How to send te XML data using HTTPS post call & receiving response in ML

    ur present design does the HTTP post for XML data using PL/SQL stored procedure call to a Java program embedded in Oracle database as Oracle Java Stored procedure. The limitation with this is that we are able to do HTTP post; but with HTTPS post; we are not able to achieve because of certificates are not installed on Oracle database.
    we fiond that the certificates need to be installed on Oracle apps server; not on database server. As we have to go ultimately with HTTPS post in Production environment; we are planning to shift this part of program(sending XML through HTTPS post call & receiving response in middle layer-Apps server in this case).
    how i can do this plz give some solution

    If you can make the source app to an HTTP Post to the Oracle XML DB repository, and POST contains a schema based XML document you can use a trigger on the default table to validate the XML that is posted. The return message would need to be managed using a database trigger. You could raise an HTTP error which the source App would trap....

  • How to validate Date

    Hi,
    We have a date field in the form. I am validating date format as YYYY-MM-DD, validation works fine. But If user enters invalid date, how to validate date? For examples:
    2006-02-31 It is an invalid date. How can i validate it.
    If anybody have sample code, it will help me a lot.
    thanks
    Neopal.

    Hi Neopal,
    You can use something like the following to test the date is valid, use the validation event on the <Field> which you want to validate to call a Rule something like this (not complete)..
      <Rule name='isDateValid'>
            <RuleArgument name='date'/>
            <block>
           <script>
              var dateToTest = env.get('date');
              var formatter = new java.text.SimpleDateFormat('YYYY-MM-DD');
              Date validDate = formatter.parse(dateToTest);

  • Function Module to validate date

    Hi,
    Is there a Function module to validate date in transfer rules or update rules. I checked the forum, couldn't find an answer. Any help is appreciated
    Thanks
    Bala

    You should be able to use this FM:
    CALL FUNCTION 'RSAR_DATE_CHECK_PLAUSIBILITY'
      EXPORTING
        i_date                          = yourdate
    EXCEPTIONS
       PLAUSIBILITY_CHECK_FAILED       = 1

  • Validate Date Range in inputDate component

    Hi
    I am using JDev 11.1.1.2.0
    I have an inputDate component which on click i need to give dates from today to future dates not passed dates.
    So i have included 'validate date time range' component in the inputDate component and in the minimum property i have declared 'adf.currentDate' using expression builder and set the maximum as Jan 31,2099.
    But when i execute my application i am able to select passed dates using the inputDate component, please help how can i check the date using a validator in inputDate component.
    Thanks
    Sudeep

    ya i had tried with that property too....
    i have declared minValue as adf.currentDate and on that it changes the value of maxValue to current date in Jan 3,2012
    i have convertDatetime component in my inputDate to display the selected date in certain format.
    It gives error as the format doesnot matches with the convertDatetime and inputDate component.
    How can i use the minValue and maxValue of inputDate component?
    the component:-
    <af:inputDate
    label="Planned Termination Date"
    id="id2"
    value="#{modifyuser.pterminationdate}"
    valueChangeListener="#{modifyuserfields.plannedTermDate}"
    minValue="adf.currentDate" maxValue="2099-12-31">
    <af:convertDateTime pattern="dd-MMM-yyyy"/>
    </af:inputDate>

  • Validate date ?

    Dear All,
    May I enquire how to validate date for:
    textDateofLoss.getText()
    Is it:
    if isDate(textDateofLoss.getText()){
    //True date
    else{
    //False date}
    Please advise.

    Sorry, have to use the following:
    import java.util.*;
    import java.text.*;
    public class validateDate {
    public static void main(String args[]) {
    String dt = "10-10-1990";
    String format = "dd-mm-yyyy";
    // String dt = "1990-10/10" throws a ParseException
    // String dt = "1990-10-35" throws a IllegalArgumentException
    try {
    //DateFormat df =
    //DateFormat.getDateInstance(DateFormat.SHORT);
    SimpleDateFormat df = new SimpleDateFormat(format);
    df.setLenient(false); // this is important!
    Date dt2 = df.parse(dt);
    System.out.println("Date is ok = " + dt2);
    catch (ParseException e) {
    System.out.println(e.getMessage());
    catch (IllegalArgumentException e) {
    System.out.println("Invalid date");
    }

  • Validate date of Birth

    How I can validate date of birth?
    Month-Date-Year
    Example: 11-21-1960
    Thanks

    You could use a regular expression:
    E.g.
    var dateRegExp = "^(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])-(19|20)\d\d$"; // mm-dd-yyyy
    if (oField.rawValue.search(dateRegExp) === -1) {
         // error!
    Or you could use a date object as suggested in the previous post, but also stop the user from typing in a date so they will be forced to use the date selection box. This would ensure that the date is always in the correct format. To stop the user from typing in data, put the following code in the change event for the field:
    if (xfa.event.change.length == 1) {
    xfa.event.change = "";

  • Validate Date and block JavaScript page change

    how I can validate date acrobat, can block JavaScript page change, only change with a button? 

    If you use the "util.scand" method date validation is part of the process. It either returns the number of milliseconds from the Epoch date used by JavaScript for the date time object the null value.
    Date Arithmetic has some sample scripts, but you need to keep in mind that Date and Time are not independent and using "new Date()" returns the date and time at the time that line of code is executed and that can cause issues for the computing of dates only.
    Are you sure of day count, most differences include the start and end dates in the number of days for the calculation.
    Custom calculation for today's date field (format is None):
    // get today's date an time
    var oToday = new Date();
    // set to start of day
    oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(), oToday.getDate(), 0, 0, 0, 0)
    // set field value
    event.value = util.printd("d/mm/yyyy", oToday);
    Custom calculation for the difference in days field (format None):
    var cEnteredDate = this.getField("EnteredDate").value;
    var cToday = this.getField("Today").value;
    event.value = "";
    if(cEnteredDate != "" && cToday != "") {
    // process only if date values not empty
    // convert date strings to date time objectat midnight
    var oEnteredDate = util.scand("d/mm/yyyy", cEnteredDate );
    if (oEnteredDate == null) {
    app.alert("Error in processing entered date", 2, 0);
    oEnteredDate.setFullYear(oEnteredDate.getFullYear(), oEnteredDate.getMonth(),oEnteredDate.getDate(), 0, 0, 0, 0) 
    var oToday = util.scand("d/mm/yyyy", cToday);
    if(oToday ==  null) {
    app.alert("Error converting today", 2,0);
    oToday.setFullYear(oToday.getFullYear(), oToday.getMonth(),oToday.getDate(), 0, 0, 0, 0) 
    // convert date objects to days
    var nEnteredDate = Math.floor(oEnteredDate.getTime() / (1000 * 60 * 60 * 24));
    var nToday = Math.floor(oToday.getTime() / (1000 * 60 * 60 * 24));
    // compute & format the difference
    event.value = util.printf("%,0 1.0f", (nToday - nEnteredDate));

  • [BPC 7.5] or [BPC 10] Validate data from different periods

    Hi,
    is it possible to use the standard validation business rule to validate data in different periods? I need a rule that validates the total in my flow dimension from last year end to the value in the opening flow in the current period. Is that possible?
    Thanks,
    Arnold

    Hi Arnold,
    I do not think this is possible. You can only compare accounts and flows in the detailed rules. In the Header rules you can specify specific dimensions and time periods.
    You can maybe use script logic to write data to the current month into a validation test account from the last year into the current period and then run the validation rules.
    Thanks,
    John

  • RegEx to validate date between 1900 & today

    Hi,
    I have a RegEx which validates the date of birth
    (0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)dd
    But I want it to validate date of birth until today only from 1900
    How can I do that using regular expression?
    a®s
    Edited by: a®s on Jul 2, 2008 3:00 PM

    Thanks for your reply Jan.
    Jan Stallkamp wrote:
    > In general regex tend to be easy to write but hard to read. So from a maintance perspective they might not be the best choice. >
    I accept the fact that you mentioned above.
    I am planning different RegEx for different date formats.
    This application need to be called from a PHP page. so don't find any other way to tackle this issue.
    Any other info?

  • Exit to validate data in CJ01

    Hi experts ,
    I have a issue in Exits . I need to validate data in CJ01 Project Definition data .
    Exactly is there any Badi or Userexit to validate the data at SAVE of the CJ01.
    Regards,
    Sandeep thota.

    Thats a very generic question. You can use various methods for that
    1. Use script task and include your validation logic
    2. Use derived column transform and do validation using ssis functions and return boolean result based on outcome
    3. Get details onto staging table, use t-sql stored procedure etc
    If you can explain exact scenario we may be able to suggest more specific answer.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Differences & advantages/disadvantages using OCFS & OMF

    Differences & advantages/disadvantages using "OCFS & OMF" against "ServiceGuard & Veritas CFS" in a RAC implementation

  • Role creation: SAP ALL with SU01 and PFCG in display only

    hi all, I am looking for the easiest way to create a "sap all " like role with SU01 and PFCG in display only. i found several solutions, which sound very complicated. Thank you in advance, Julien

  • Error in exporting application

    I am trying to export an application and it gives me error app.report unable to gte the component id . this report does not exist with me. when I try to create the report with the same name it says that this report already exists. now I can not do an

  • (no inline validation error displayed)) condition type and plsql expression

    Hello all Is it possible to use a plsql expression (eg: (:REQUEST = 'PXX_LIST_ITEM')) AND (no inline validation error displayed)) condition type at the smae time ? HTMLDB must be testing a substitution variable when the conditional display section is

  • Creating posting run contains no document.

    hI EXPERTS, THIS MESSAGE COMMING DURING THE POSTING RUN "Creating posting run contains no documents" but i have seen past solution which is mentioned in Dec 08.  they are not working , psl give some real time answers, it very crtical stage of project