有效日期为5日 [英] Validdate date is befour 5th

查看:102
本文介绍了有效日期为5日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加日期验证,例如



用户只能在月份的1-5个月内插入上个月的数据



如果当前日期大于5 th那么它不应该允许输入数据





谢谢

解决方案

使用 DateTime.Day property [ ^ ]。

试试

 if(curretDate.Day> = 1 || currentDate< = 5)
{
// Insert
}


我已经解决了这个





  int  CurrentMonth = Convert.ToInt32(DateTime.Today.Month)
int CurrentDate = Convert.ToInt32(DateTime.Now 。天);
int CurrentYear = Convert.ToInt32(DateTime.Now.Year); if (!(CurrentMonth == Convert.ToInt32(obj.Challan_Date.Month)&&& CurrentYear == Convert.ToInt32(obj.Challan_Date.Year)))
{
if (CurrentDate > 5
{
throw new DataException(< span class =code-string> 上个月challan在每个月的5号之后无法插入。); // 除了具有特殊权利的用户(按照Malek的要求删除)
}
}


 DateTime InputDate = DateTime.Now;  //  您可以将日期替换为当前日期 
if (InputDate.Day > = 1 &&& InputDate.Day < = 5
{
// 成功代码
}
其他
{
// 错误代码
}


i want to add date validation like

User can only insert previous month data within 1-5 of evry month

if current date is greater than 5 th then It should not allow to enter the data


Thank you

解决方案

Use the DateTime.Day property[^].
Try

if (curretDate.Day >= 1 || currentDate <=5)
{
   //Insert
}


I have solved this


int CurrentMonth = Convert.ToInt32(DateTime.Today.Month)
 int CurrentDate = Convert.ToInt32(DateTime.Now.Day);
 int CurrentYear = Convert.ToInt32(DateTime.Now.Year); if(! (CurrentMonth == Convert.ToInt32(obj.Challan_Date.Month) && CurrentYear == Convert.ToInt32(obj.Challan_Date.Year) ))
        {
             if (CurrentDate > 5)
                  {
                    throw new DataException("Previous Months challan can not be inserted after 5th of every month."); // except User having special rights (Removed at behest of Malek)
                    }
         }


DateTime InputDate = DateTime.Now; //You can replace your date with current date
if(InputDate.Day >= 1 && InputDate.Day <= 5)
{
//Success code
}
else
{
//Error code
}


这篇关于有效日期为5日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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