Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Comments
Maciej Los 11-Apr-14 5:27am    
What's the question? What have you done till now? Where are you stuck?
Ankita M 11-Apr-14 6:13am    
int CurrentMonth = Convert.ToInt32(DateTime.Today.Month);
int CurrentDate = Convert.ToInt32(DateTime.Now.Day);
int CurrentYear = Convert.ToInt32(DateTime.Now.Year);

but it is not working correctly
if my date is between 1-4 then also it is not allowing me to enter data
if ( !(CurrentMonth == Convert.ToInt32(obj.Challan_Date.Month) && (CurrentDate <= 5) && (CurrentYear == Convert.ToInt32(obj.Challan_Date.Year) )))
{
throw new DataException("Previous Months challan can not be deleted after 5th of every month."); // except User having special rights (Removed at behest of Malek)
}

Use the DateTime.Day property[^].
Try
if (curretDate.Day >= 1 || currentDate <=5)
{
   //Insert
}
 
Share this answer
 
I have solved this


C#
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)
                    }
         }
 
Share this answer
 
C#
DateTime InputDate = DateTime.Now; //You can replace your date with current date
if(InputDate.Day >= 1 && InputDate.Day <= 5)
{
//Success code
}
else
{
//Error code
}
 
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