在C#.net中验证日期 [英] Validation for date in C#.net

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

问题描述

I want a validation for date in C# .net it cannot be future date and cannot be back dated more than one week. any one please help

推荐答案

您可以在代码中写条件来检查日期





试试这个



You can write condition within your code to check the date


try this

if (yourdate <=DateTime.Now && yourdate >=DateTime.Now.AddDays(-7))
            {
                
            }


check DateTime.Today Property(System) [ ^ ]和DateTime.AddDays Method(Double)(System) [ ^ ]

您需要将给定日期与DateTime.Today和7天后的日期进行比较。具有减值参数的DateTime.AddDays方法将减少从给定日期开始的天数,因此您可以使用它来查找日期前7天。除此之外,你需要C#如果条件。试试自己。
check DateTime.Today Property (System)[^] and DateTime.AddDays Method (Double) (System)[^]
You need to compare given date with DateTime.Today and Date in 7 days back. DateTime.AddDays method with minus value parameter will reduce the days from given date, so you can use that to find 7 days before date. other than that you need C# if conditions. Try yourself.


学习比较和日期时间值的算术运算 [ ^ ]


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

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