Link to home
Start Free TrialLog in
Avatar of jaws1021
jaws1021

asked on

date format

what is the date validationexpression for format yyyymmdd ? It also should be good for leap year.
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

yyyyMMdd is this that you want ?
Avatar of jaws1021
jaws1021

ASKER

yes please
Plus you can use ASP.NET Compare Validator to validate a date on both Client side (depending on the browser) and it can also be accessed on the server side...

<asp:CompareValidator ID="compareDate" runat="server" ControlToCompare="txtDateTextbox" Operator="DataTypeCheck" Type="Date" ErrorMessage="Chack Date" />

This does format the date as MM/DD/YYYY and I know that you said you wanted it the other way around, but i thought that the Compare Validator is an easy validation tool...

John
I am using regular expression validation and I need this format yyyyMMdd . I looked at that link but didn;t help me that much..
Try this one, there aer several on the page:

http://regexlib.com/Search.aspx?k=date%20format

Also, you can reformat the date once you have it in one forma or another.

Using Javascript:

http://www.w3schools.com/jsref/jsref_obj_date.asp

Or VBScript on server side

Year() & "-" & Month() & "-" & Day()

There are a lot of choices once you have the date in a variable...

John
   protected void Page_Load(object sender, EventArgs e)
    {
        //DateTime  oldString = Convert.ToDateTime("Wed, 5 Sep 2007 07:56:04");
        //string newstring=oldString.ToString("yyyy-MM-dd HH:mm:ss");

        cmdSignIn.Attributes.Add("OnClick", "return checkDate('06/09/2007');");
    }

============================
.ASPX
<script>
function checkDate(value){
    var dateregex=/^[ 0]*(\d{1,2})\/(\d{1,2})\/(\d{4,}) *$/;
    var match=value.match(dateregex);
    if (match) {
         var tmpdate=new Date(match[3],parseInt(match[1])-1,match[2]);
         if (tmpdate.getDate()==parseInt(match[2]) && tmpdate.getFullYear()==parseInt(match[3]) && (tmpdate.getMonth()+1)==parseInt(match[1])){
             alert ( 'Y;')
             return true;
             }
    }
      alert ( 'Nope;')
    return false;
}

</script>
    <form id="form1" runat="server">
    <asp:Button    ID="cmdSignIn" runat="server" Text ="click me"/>    
    </form>

Check date using script. i hope thiw will help you

Regards,
M.Raja
ASKER CERTIFIED SOLUTION
Avatar of raja_ind82
raja_ind82
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial