Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. date validation plz help me................ plz

date validation plz help me................ plz

Scheduled Pinned Locked Moved C#
helptutorial
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    P_Elza
    wrote on last edited by
    #1

    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:

    C V 2 Replies Last reply
    0
    • P P_Elza

      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:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      P 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        P Offline
        P Offline
        P_Elza
        wrote on last edited by
        #3

        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.

        C 1 Reply Last reply
        0
        • P P_Elza

          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.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 1 Reply Last reply
          0
          • C Christian Graus

            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 Offline
            P Offline
            P_Elza
            wrote on last edited by
            #5

            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.

            J G 2 Replies Last reply
            0
            • P P_Elza

              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.

              J Offline
              J Offline
              Jacky Yiu
              wrote on last edited by
              #6

              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 }

              1 Reply Last reply
              0
              • P P_Elza

                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.

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                That's because you are comparing the values as strings. If you just compare the DateTime values, it's not a problem.

                --- single minded; short sighted; long gone;

                1 Reply Last reply
                0
                • P P_Elza

                  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:

                  V Offline
                  V Offline
                  V 0
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups