Connecting Tech Pros Worldwide Forums | Help | Site Map

ASP Date problem

Member
 
Join Date: Oct 2008
Posts: 58
#1: Oct 7 '08
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

Expand|Select|Wrap|Line Numbers
  1.     if IsDate(rs("DOB")) then
  2.      Response.Write(CDate(pwd) & "<br>")  --- output is (11/2/90)
  3.      Response.Write(rs("DOB") & "<br>") --- output is (2/11/90)
  4.    else
  5.      Response.Write("Error")
  6.    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.......
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. dim uname
  4. dim pwd, password, varDate 
  5. uname = Request.Form("txtUname")
  6. uname = UCASE(uname)
  7. Session.Contents("IDNO") = uname
  8. pwd = Request.Form("txtPwd")
  9. Set rs = Server.CreateObject("ADODB.Recordset")
  10. Set rs.ActiveConnection = my_Conn
  11. rs.Open "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "'", my_Conn, 1
  12. if rs.RecordCount = 0 then
  13.  rs.Close
  14.  my_Conn.Close
  15.  set rs=nothing
  16.  set my_Conn=nothing
  17.  Response.Redirect("verify.asp?Submit=namefailed")
  18. end if
  19. if isdate(pwd) then
  20. if rs("DOB")= CDate(pwd) then
  21.  rs.Close
  22.  my_Conn.Close
  23.  set rs=nothing
  24.  set my_Conn=nothing
  25.  Response.Redirect("verifyParticulars.asp")
  26. end if
  27. else 
  28.  alert("Wrong Password Format")
  29. end if
  30.  rs.Close
  31.  my_Conn.Close
  32.  set rs=nothing
  33.  set my_Conn=nothing
  34.  Response.Redirect("verify.asp?Submit=passfailed")
  35.  
  36. %>

Member
 
Join Date: Oct 2008
Posts: 58
#2: Oct 7 '08

re: 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

Expand|Select|Wrap|Line Numbers
  1. if IsDate(rs("DOB")) then
  2. Response.Write(CDate(pwd) & "<br>") --- output is (11/2/90)
  3. Response.Write(rs("DOB") & "<br>") --- output is (2/11/90)
  4. else
  5. Response.Write("Error")
  6. 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.......
Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim uname
  3. dim pwd, password, varDate 
  4. uname = Request.Form("txtUname")
  5. uname = UCASE(uname)
  6. Session.Contents("IDNO") = uname
  7. pwd = Request.Form("txtPwd")
  8. Set rs = Server.CreateObject("ADODB.Recordset")
  9. Set rs.ActiveConnection = my_Conn
  10. rs.Open "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "'", my_Conn, 1
  11. if rs.RecordCount = 0 then
  12. rs.Close
  13. my_Conn.Close
  14. set rs=nothing
  15. set my_Conn=nothing
  16. Response.Redirect("verify.asp?Submit=namefailed")
  17. end if
  18. if isdate(pwd) then
  19. if rs("DOB")= CDate(pwd) then
  20. rs.Close
  21. my_Conn.Close
  22. set rs=nothing
  23. set my_Conn=nothing
  24. Response.Redirect("verifyParticulars.asp")
  25. end if
  26. else 
  27. alert("Wrong Password Format")
  28. end if
  29. rs.Close
  30. my_Conn.Close
  31. set rs=nothing
  32. set my_Conn=nothing
  33. Response.Redirect("verify.asp?Submit=passfailed")
  34.  
  35. %>
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#3: Oct 7 '08

re: ASP Date problem


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
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#4: Oct 7 '08

re: ASP Date problem


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
Member
 
Join Date: Oct 2008
Posts: 58
#5: Oct 8 '08

re: ASP Date problem


Quote:

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...

Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. dim uname
  4. dim pwd, password, changepwd
  5. dim mm, dd, yy, mmddyy, repwd
  6.  
  7. uname = Request.Form("txtUname")
  8. uname = UCASE(uname)
  9. Session.Contents("IDNO") = uname
  10. Session.Timeout = 120
  11.  
  12. pwd = Request.Form("txtPwd")
  13.  
  14. repwd=Replace(pwd,"/","_")
  15.  
  16. dd = Mid(repwd,1,2)
  17. mm = Mid(repwd,4,2)
  18. yy = Mid(repwd,7,2)
  19.  
  20. mmddyy = mm & "/" & dd & "/19" & yy  
  21.  
  22. Set rs = Server.CreateObject("ADODB.Recordset")
  23. Set rs.ActiveConnection = my_Conn
  24.  
  25. rs.Open "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "'", my_Conn, 1
  26.  
  27.  
  28. if rs.RecordCount = 0 then
  29.  rs.Close
  30.  my_Conn.Close
  31.  set rs=nothing
  32.  set my_Conn=nothing
  33.  Response.Redirect("verify.asp?Submit=namefailed")
  34. end if
  35.  
  36. if isdate(mmddyy) then
  37. password = FormatDateTime(mmddyy,0)
  38. if rs("DOB")= CDate(password) then
  39.  rs.Close
  40.  my_Conn.Close
  41.  set rs=nothing
  42.  set my_Conn=nothing
  43.  Response.Redirect("verifyParticulars.asp")
  44. end if
  45. else 
  46.  end if
  47.  rs.Close
  48.  my_Conn.Close
  49.  set rs=nothing
  50.  set my_Conn=nothing
  51.  Response.Redirect("verify.asp?Submit=passfailed")
  52. %>
Regards,
susan
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#6: Oct 8 '08

re: ASP Date problem


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
Member
 
Join Date: Oct 2008
Posts: 58
#7: Oct 9 '08

re: ASP Date problem


Quote:

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
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#8: Oct 9 '08

re: ASP Date problem


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
Reply


Similar ASP / Active Server Pages bytes