Click here to Skip to main content
14,667,837 members
Rate this:
Please Sign up or sign in to vote.
down vote favorite

i'm using 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

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100