date validation plz help me................ plz
-
hai all i have 2 date column, receive date n due date. RD should be greater than DD. am entering the date in the form dd/mm/yyyy. and For validation am using a function validatedate. the code is given below.
string dd=Convert.ToString(fld.Month);
string dd1=Convert.ToString(fld1.Month);
string mm=Convert.ToString(fld.Day);
string mm1=Convert.ToString(fld1.Day);
string yy=Convert.ToString(fld.Year);
string yy1=Convert.ToString(fld1.Year);
string date=mm+"/"+dd+"/"+yy;
string date1=mm1+"/"+dd1+"/"+yy1;
if((String.Compare(yy,yy1)>0)||(String.Compare(mm,mm1)>0)||((String.Compare(dd,dd1)>0)&&(String.Compare(mm,mm1)==0))||((String.Compare(dd,dd1)<=0)&&(String.Compare(mm,mm1)>0)))
{
lblmsg.Text="error";
RegisterStartupScript("startup","window.alert('Error:"+date.ToString()+">"+date1.ToString()+" ')");
}
else
{
RegisterStartupScript("startup","window.alert('correct:"+date1.ToString()+">"+date.ToString()+" ')");
}but for 1,2,3,up to 9 it is taking only one digit and not validation properly. how to include 0 also along with the date. plz help me. plz...... i poted a quest before. but didnt get any reply. so i tried it in this format. plz do help me:confused:
-
hai all i have 2 date column, receive date n due date. RD should be greater than DD. am entering the date in the form dd/mm/yyyy. and For validation am using a function validatedate. the code is given below.
string dd=Convert.ToString(fld.Month);
string dd1=Convert.ToString(fld1.Month);
string mm=Convert.ToString(fld.Day);
string mm1=Convert.ToString(fld1.Day);
string yy=Convert.ToString(fld.Year);
string yy1=Convert.ToString(fld1.Year);
string date=mm+"/"+dd+"/"+yy;
string date1=mm1+"/"+dd1+"/"+yy1;
if((String.Compare(yy,yy1)>0)||(String.Compare(mm,mm1)>0)||((String.Compare(dd,dd1)>0)&&(String.Compare(mm,mm1)==0))||((String.Compare(dd,dd1)<=0)&&(String.Compare(mm,mm1)>0)))
{
lblmsg.Text="error";
RegisterStartupScript("startup","window.alert('Error:"+date.ToString()+">"+date1.ToString()+" ')");
}
else
{
RegisterStartupScript("startup","window.alert('correct:"+date1.ToString()+">"+date.ToString()+" ')");
}but for 1,2,3,up to 9 it is taking only one digit and not validation properly. how to include 0 also along with the date. plz help me. plz...... i poted a quest before. but didnt get any reply. so i tried it in this format. plz do help me:confused:
so what's wrong with if (fld > fld1) ???
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
so what's wrong with if (fld > fld1) ???
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
since am inserting value as dd/mm/yyyy,the system is taking this as mm/dd/yyyy. to validate that i wrote all these code. but still am finding some error.
P_Elza wrote:
since am inserting value as dd/mm/yyyy,the system is taking this as mm/dd/yyyy
So what ? A datetime is a datetime. What you're talking about is a rendering detail. If you're getting a date as a string, parse it with DateTime.TryParse and specify the format used. Then you have a datetime object. It doesn't care what order you want the date in, it has the values individually named.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
P_Elza wrote:
since am inserting value as dd/mm/yyyy,the system is taking this as mm/dd/yyyy
So what ? A datetime is a datetime. What you're talking about is a rendering detail. If you're getting a date as a string, parse it with DateTime.TryParse and specify the format used. Then you have a datetime object. It doesn't care what order you want the date in, it has the values individually named.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
am getting the date as datetime format only. it is working only for small dates like below 20 and within one month. if it goes to 2 different month, it is taking only one value. and not showing the error also. if the 2 dates r 02/10/2007 n 22/10 2007 also it is not working. and i tried with what u said. the same problem is comming.
-
am getting the date as datetime format only. it is working only for small dates like below 20 and within one month. if it goes to 2 different month, it is taking only one value. and not showing the error also. if the 2 dates r 02/10/2007 n 22/10 2007 also it is not working. and i tried with what u said. the same problem is comming.
will it become easy to use CompareTo in your case? two DateTime object: DateTime dt1 = new DateTime(2007, 10, 2); DateTime dt2 = new DateTime(2007, 10, 22); int result = dt1.CompareTo(dt2); if (result == 1) { //dt1 is after dt2 } else if (result == -1) { //dt2 is after dt1 } else if (result == 0) { //dt1 is equal to dt2 }
-
am getting the date as datetime format only. it is working only for small dates like below 20 and within one month. if it goes to 2 different month, it is taking only one value. and not showing the error also. if the 2 dates r 02/10/2007 n 22/10 2007 also it is not working. and i tried with what u said. the same problem is comming.
-
hai all i have 2 date column, receive date n due date. RD should be greater than DD. am entering the date in the form dd/mm/yyyy. and For validation am using a function validatedate. the code is given below.
string dd=Convert.ToString(fld.Month);
string dd1=Convert.ToString(fld1.Month);
string mm=Convert.ToString(fld.Day);
string mm1=Convert.ToString(fld1.Day);
string yy=Convert.ToString(fld.Year);
string yy1=Convert.ToString(fld1.Year);
string date=mm+"/"+dd+"/"+yy;
string date1=mm1+"/"+dd1+"/"+yy1;
if((String.Compare(yy,yy1)>0)||(String.Compare(mm,mm1)>0)||((String.Compare(dd,dd1)>0)&&(String.Compare(mm,mm1)==0))||((String.Compare(dd,dd1)<=0)&&(String.Compare(mm,mm1)>0)))
{
lblmsg.Text="error";
RegisterStartupScript("startup","window.alert('Error:"+date.ToString()+">"+date1.ToString()+" ')");
}
else
{
RegisterStartupScript("startup","window.alert('correct:"+date1.ToString()+">"+date.ToString()+" ')");
}but for 1,2,3,up to 9 it is taking only one digit and not validation properly. how to include 0 also along with the date. plz help me. plz...... i poted a quest before. but didnt get any reply. so i tried it in this format. plz do help me:confused:
if(DateTime.TryParseExact(fieldtext, DATETIMEPATTERN, null, DateTimeStyles.None, out doctime)) {
//DATETIME is a valid DATETIME
}fieldtext is the string representation of the date eg "23/04/1978", DATETIMEPATTERN is the format "dd/MM/yyyy". doctime will contain a valid DateTime object if the method returns true. For more info, check out the MSDN website. A general hint, work with DateTime objects as much as possible and use the DateTime's ToString method at the very last moment... good luck.
V. No hurries, no worries