ASP Date problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shivasusan
    New Member
    • Oct 2008
    • 67

    #1

    ASP Date problem

    Hello Friend!

    I am new for ASP. Database is Microsoft Access. So pls help me.....

    My problem is ---

    1. In login page, two text boxs. first textbox is username & second textbox is Password. Password is Date of Birth.

    If DOB is starting 09-08-90 or 11-01-91 is not login or DOB is starting more than 13 (13-03-91 or 28-11-91) is succefully login.
    2. So I check, How? the date is print. Below code

    Code:
        if IsDate(rs("DOB")) then
         Response.Write(CDate(pwd) & "<br>")  --- output is (11/2/90)
         Response.Write(rs("DOB") & "<br>") --- output is (2/11/90)
       else
         Response.Write("Error")
       end if
    3. How i can solve this?
    4.Because in my program, I check the ( if rs("DOB")= CDate(pwd) then)
    Pls check the below coding... and reply me immediately is very very urgent advances thanks.......
    Code:
     
    <%
    dim uname
    dim pwd, password, varDate 
    uname = Request.Form("txtUname")
    uname = UCASE(uname)
    Session.Contents("IDNO") = uname
    pwd = Request.Form("txtPwd")
    Set rs = Server.CreateObject("ADODB.Recordset")
    Set rs.ActiveConnection = my_Conn
    rs.Open "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "'", my_Conn, 1
    if rs.RecordCount = 0 then
     rs.Close
     my_Conn.Close
     set rs=nothing
     set my_Conn=nothing
     Response.Redirect("verify.asp?Submit=namefailed")
    end if
    if isdate(pwd) then
    if rs("DOB")= CDate(pwd) then
     rs.Close
     my_Conn.Close
     set rs=nothing
     set my_Conn=nothing
     Response.Redirect("verifyParticulars.asp")
    end if
    else 
     alert("Wrong Password Format")
    end if
     rs.Close
     my_Conn.Close
     set rs=nothing
     set my_Conn=nothing
     Response.Redirect("verify.asp?Submit=passfailed")
    
    %>
    Last edited by DrBunchman; Oct 7 '08, 09:00 AM. Reason: Added [Code] Tags - Please use the '#' button
  • shivasusan
    New Member
    • Oct 2008
    • 67

    #2
    Using MS-Access Database If statement error in ASP

    Hello Friend!

    I am new for ASP. Database is Microsoft Access. So pls help me.....

    My problem is ---

    1. In login page, two text boxs. first textbox is username & second textbox is Password. Password is Date of Birth.

    If DOB is starting 09-08-90 or 11-01-91 is not login or DOB is starting more than 13 (13-03-91 or 28-11-91) is succefully login.
    2. So I check, How? the date is print. Below code

    Code:
    if IsDate(rs("DOB")) then
    Response.Write(CDate(pwd) & "<br>") --- output is (11/2/90)
    Response.Write(rs("DOB") & "<br>") --- output is (2/11/90)
    else
    Response.Write("Error")
    end if
    3. How i can solve this?
    4.Because in my program, I check the ( if rs("DOB")= CDate(pwd) then)
    Pls check the below coding... and reply me immediately is very very urgent advances thanks.......
    Code:
    <%
    dim uname
    dim pwd, password, varDate 
    uname = Request.Form("txtUname")
    uname = UCASE(uname)
    Session.Contents("IDNO") = uname
    pwd = Request.Form("txtPwd")
    Set rs = Server.CreateObject("ADODB.Recordset")
    Set rs.ActiveConnection = my_Conn
    rs.Open "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "'", my_Conn, 1
    if rs.RecordCount = 0 then
    rs.Close
    my_Conn.Close
    set rs=nothing
    set my_Conn=nothing
    Response.Redirect("verify.asp?Submit=namefailed")
    end if
    if isdate(pwd) then
    if rs("DOB")= CDate(pwd) then
    rs.Close
    my_Conn.Close
    set rs=nothing
    set my_Conn=nothing
    Response.Redirect("verifyParticulars.asp")
    end if
    else 
    alert("Wrong Password Format")
    end if
    rs.Close
    my_Conn.Close
    set rs=nothing
    set my_Conn=nothing
    Response.Redirect("verify.asp?Submit=passfailed")
    
    %>
    Last edited by DrBunchman; Oct 7 '08, 09:03 AM. Reason: Added [Code] Tags - Please use the '#' button

    Comment

    • DrBunchman
      Recognized Expert Contributor
      • Jan 2008
      • 979

      #3
      Hi shivasusan,

      Welcome to Bytes.com. Please don't double post your questions - it is against the rules laid out in the Posting Guidelines. If you wish to add more information or you want to 'bump' your thread back to the top of the list then you can simply reply to it.

      Please don't forget to wrap your code in CODE tags - it makes your posts much easier to read.

      You have posted another question about date formatting in the forum which I have answered - does this help you with the problem above? If not can you try to explain your problem again as i'm not sure what it is - are you getting an error?

      Dr B

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        This is a common problem. In the US the standard date format is mm/dd/yy (because we would say October 7th rather than 7th of October) whereas in the rest of the English-speaking world the standard date format is dd/mm/yy. Since MS is a US-based company, unless you specify otherwise, all MS products assume that date in US format is correct, but dates in other formats are incorrect and are recorded as text, not as a date. To resolve this issue, all dates must be saved in unambiguous date formats (such as 2008-Oct-07 or 07-Oct-2008) or specify that this field in the db is a text field rather than a date field.

        Jared

        Comment

        • shivasusan
          New Member
          • Oct 2008
          • 67

          #5
          Originally posted by jhardman
          This is a common problem. In the US the standard date format is mm/dd/yy (because we would say October 7th rather than 7th of October) whereas in the rest of the English-speaking world the standard date format is dd/mm/yy. Since MS is a US-based company, unless you specify otherwise, all MS products assume that date in US format is correct, but dates in other formats are incorrect and are recorded as text, not as a date. To resolve this issue, all dates must be saved in unambiguous date formats (such as 2008-Oct-07 or 07-Oct-2008) or specify that this field in the db is a text field rather than a date field.

          Jared
          Hi Jared!

          Thanks for your reply.

          I try to convert the date dd/mm/yy to mm/dd/yy. I got answer, but i don't know its correct way. Please check my coding and reply me...

          Code:
          <%
          
          dim uname
          dim pwd, password, changepwd
          dim mm, dd, yy, mmddyy, repwd
          
          uname = Request.Form("txtUname")
          uname = UCASE(uname)
          Session.Contents("IDNO") = uname
          Session.Timeout = 120
          
          pwd = Request.Form("txtPwd")
          
          repwd=Replace(pwd,"/","_")
          
          dd = Mid(repwd,1,2)
          mm = Mid(repwd,4,2)
          yy = Mid(repwd,7,2)
          
          mmddyy = mm & "/" & dd & "/19" & yy  
          
          Set rs = Server.CreateObject("ADODB.Recordset")
          Set rs.ActiveConnection = my_Conn
          
          rs.Open "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "'", my_Conn, 1
          
          
          if rs.RecordCount = 0 then
           rs.Close
           my_Conn.Close
           set rs=nothing
           set my_Conn=nothing
           Response.Redirect("verify.asp?Submit=namefailed")
          end if
          
          if isdate(mmddyy) then
          password = FormatDateTime(mmddyy,0)
          if rs("DOB")= CDate(password) then
           rs.Close
           my_Conn.Close
           set rs=nothing
           set my_Conn=nothing
           Response.Redirect("verifyParticulars.asp")
          end if
          else 
           end if
           rs.Close
           my_Conn.Close
           set rs=nothing
           set my_Conn=nothing
           Response.Redirect("verify.asp?Submit=passfailed")
          %>
          Regards,
          susan

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            Changing to mm/dd/yy is only a partial fix and I wouldn't do that for something that is going to stay permanent. The best permanent fix would be to change it to Mmm/dd/yyyy or some such variation where Mmm is the three-letter abbreviation for the month.

            This is the problem: If a user enters 10/12/2008 or 12/10/2008 there is no way you can be sure you know which date he means and there is no way to ensure that he will write it the same way next time (experienced internet users are used to seeing different formats requested depending on the regional location of the coder). It would be much better to select a date from a drop down list or calendar control, but I understand that is not ideal for a password.

            You could make the field be plain text in the db (varchar(8 or 10)) and then it wouldn't matter what the user entered, it would be his responsibility to get it the same way the next time.

            You could assume that all of your users are going to enter the date in the same format, then your solution is valid, but the easiest way would be to specify a different region coding in your asp script (as DrBunchman suggested in another thread recently, maybe it was posted by you, I don't remember) or in the db. But if you don't want to do that, the simplest solution would be to ask the users to enter the date in a format like this: "12/Oct/2008" or "12-Oct-2008". I have seen all sorts of variations on this format and all are accepted and interpreted correctly by the db, even when put in apparently random order. Then even if the site owner comes to you later and says, "I don't like the date format '12-Oct-2008'. Can we enter the date as 'October 12, 2008'?" and you can say, "why yes. I'll add a special patch to allow you to enter dates that way. It will cost you another $350 ." but you won't even have to do anything, because the db and the script will still know how to handle it.

            From my point of view, the solution you give has the same weakness as the original, it just assumes that the other date format will be used. Does this make sense?

            Jared

            Comment

            • shivasusan
              New Member
              • Oct 2008
              • 67

              #7
              Originally posted by jhardman
              Changing to mm/dd/yy is only a partial fix and I wouldn't do that for something that is going to stay permanent. The best permanent fix would be to change it to Mmm/dd/yyyy or some such variation where Mmm is the three-letter abbreviation for the month.

              This is the problem: If a user enters 10/12/2008 or 12/10/2008 there is no way you can be sure you know which date he means and there is no way to ensure that he will write it the same way next time (experienced internet users are used to seeing different formats requested depending on the regional location of the coder). It would be much better to select a date from a drop down list or calendar control, but I understand that is not ideal for a password.

              You could make the field be plain text in the db (varchar(8 or 10)) and then it wouldn't matter what the user entered, it would be his responsibility to get it the same way the next time.

              You could assume that all of your users are going to enter the date in the same format, then your solution is valid, but the easiest way would be to specify a different region coding in your asp script (as DrBunchman suggested in another thread recently, maybe it was posted by you, I don't remember) or in the db. But if you don't want to do that, the simplest solution would be to ask the users to enter the date in a format like this: "12/Oct/2008" or "12-Oct-2008". I have seen all sorts of variations on this format and all are accepted and interpreted correctly by the db, even when put in apparently random order. Then even if the site owner comes to you later and says, "I don't like the date format '12-Oct-2008'. Can we enter the date as 'October 12, 2008'?" and you can say, "why yes. I'll add a special patch to allow you to enter dates that way. It will cost you another $350 ." but you won't even have to do anything, because the db and the script will still know how to handle it.

              From my point of view, the solution you give has the same weakness as the original, it just assumes that the other date format will be used. Does this make sense?

              Jared
              Hi!

              Thank you, for your reply.

              I changed the db fieldname into text. But my Boss didn't accept. Try to do the fieldname in date format, Pls help me.... is any way to do these....

              Regards,
              Susan

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                Which part does your boss not like? Does he just want the db field to be a DateTime field? Does he insist the date needs to be entered by the user in a particular format?

                Jared

                Comment

                Working...