Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validate a date
Message
From
14/07/2006 15:59:45
 
 
To
14/07/2006 15:37:06
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
ASP.NET
Miscellaneous
Thread ID:
01136539
Message ID:
01136554
Views:
21
>>I have a ASP.Net webform that contains a textbox where a user should enter a date in mm/dd/yy format.
>>
>>How can I validate that the user enter a good date?
>
>Try something like this:
>
>[SNIP]


Or a quick (untested) translation from French Canadian {g}
// Return a date from a string value based on a date format
// expC1 Date
// expN1 Format
// expC2 Time
public DateTime GetDateFromString(string tcDate, int tnFormat, string tcTime)
{
    DateTime ldDate;
    int lnDay;
    int lnMonth;
    int lnYear;
    switch (tnFormat)
    {
        case 1:
            lnDay = int.Parse(tcDate.Substring(0,2));
            lnMonth = int.Parse(tcDate.Substring(3,2));
            lnYear = int.Parse(tcDate.Substring(6,4));
            break;
        case 2:
            lnDay = int.Parse(tcDate.Substring(3,2));
            lnMonth = int.Parse(tcDate.Substring(0,2));
            lnYear = int.Parse(tcDate.Substring(6,4));
            break;
        case 3:
            lnDay = int.Parse(tcDate.Substring(8,2));
            lnMonth = int.Parse(tcDate.Substring(5,2));
            lnYear = int.Parse(tcDate.Substring(0,4));
            break;
	    default:
            break;
    }

    if (tcTime.Length==0)
    {
        ldDate = new DateTime(lnYear, lnMonth, lnDay);
    }
    else
    {
        ldDate = new DateTime((lnYear, lnMonth, lnDay, 
            int.Parse(tcTime.Substring(0,2)), 
            int.Parse(tcTime.Substring(3,2)), 
            int.Parse(tcTime.Substring(6,2)));
    }
    return ldDate;
}


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform