验证asp.net中的excel日期字段 [英] Validate excel date field in asp.net

查看:97
本文介绍了验证asp.net中的excel日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向下投票最爱





我正在使用asp.net上传某个excel文件..在那个excel文件中我有一个日期字段..我需要的是比较这个日期字段与我正在使用的日期格式yyymmdd....所以我该如何验证它?



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

推荐答案

这里有很多方法可以做同样的事情,



1.因为你在dateString变量中有日期值,你可以生成所需的日期值并进行比较,

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.或试试这个


2. Or try this

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



3.你可以也使用正则表达式





谢谢,


3. you can also use regular expression


Thanks,


这篇关于验证asp.net中的excel日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆