Click here to Skip to main content
15,883,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

VB
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,
C#
DateTime dt = DateTime.ParseExact(dateString, "yyyyMMdd", CultureInfo.InvariantCulture);
string requiredDate = dt.ToString("yyyyMMdd");

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

3. you can also use regular expression


Thanks,
 
Share this answer
 

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