Click here to Skip to main content
14,690,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
down vote favorite


i'm using asp.net to upload a certain excel file.. in that excel file i have a date field..what i need is to compare this date field to the format "yyymmdd" of the date that i'm using.... so how can i validate it?

For Each row As DataRow In ExcelCntDT.Rows
             i = i + 1
             desc = row("DESCRIPTION")
             datee = row("DATE_TO_SEND")
             timee = row("TIME_TO_SEND")
             finalTime = timee.Substring(0, 5)
             content = row("CONTENT")
             If datee Then ' here i need to validate my date
                     validDate = false
             End If
Next
Posted

1 solution

Here many ways to do the same,

1. As you have date value in dateString variable, you can generate required date value and compare,
DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd", CultureInfo.InvariantCulture);
string requiredDate = dt.ToString("yyyyMMdd");

2. Or try this
DateTime dateValue;
if (DateTime.TryParseExact(dateString, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
{
 //do logic here
}

3. you can also use regular expression


Thanks,
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900