Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2004, 04:46 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compare dates [problem]...

Hello Guyz...

I have a form with a field where the user must insert his birth date. On submit I check the value if it is a date and then if this date is between logical limits. But I have a prob. The code I wrote is the following.

<form action=update_new_user2.asp method=post name=frmupdate>
    <input type=hidden name=Action value=Update>

<table>
        <tr>
        <td>Birth Date</td>
        <td><input type=text name=a4 size=30</td></tr>


<tr>
<td height=60><input type=button name=btnSubmit1 value=Insert></td>
</tr>
    </table>
     </form>


<script language=vbscript>
Sub btnSubmit1_OnClick()


If Len(frmupdate.a4.value) = 0 OR NOT IsDate(frmupdate.a4.value) Then
Alert "You have to insert date (dd/mm/yyyy)"
    frmupdate.a4.focus
    Exit sub

       ElseIf (frmupdate.a4.value) < "1/1/1940" OR (frmupdate.a4.value) > "1/1/1980" Then
        Alert "You have to insert right date"
        frmupdate.a4.focus
        Exit sub
End If

    Call frmUpdate.submit()
End Sub
</script>



The problem with this code is that if the user try to insert for example 1/1/1960 everything will work fine. But if he try to insert 2/1/1960 or anyother value for month and date other than 1/1 then the senond Alert box comes up.

Plzzz... help me with that..
 
Old August 18th, 2004, 08:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. you are making the comparations like there where strings, not dates..
i dont konw how to do it in script.. maybe you have datediff=???
or something like that to convert every to date???

other things i do is to format dates like yyyymmdd, and then compare them in string.. always work...

HTH

Gonzalo
 
Old August 19th, 2004, 02:03 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your reply is very helpful. I think that I have to convert it to a string like yyyymmdd eventually although I would like to avoid this.

But if I should use "substrings" then I think that it would be better if I use 3 listboxes (dd)(mm)(yyyy) [than using a simple "textbox"] in order to make the date again.

What`s your opinion about that?

                  Vagelis!

P.S. I`m just looking for the easier best solution :P
P.S. [I`m a newbie!]
 
Old August 20th, 2004, 09:55 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I solved the problem. And actually it was quite easy to be used!

ElseIf (Year(frmupdate.a4.value)) < 1940 OR (Year(frmupdate.a4.value)) > 1980 Then
        Alert "You have to insert right date"
        frmupdate.a4.focus
        Exit sub
End If


-------------
this is the solution. (Year(value)) returns yyyy.
I feel good to solve this and a bit stupid that I had a prob like this...





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compare two dates lakshmi_annayappa Javascript 1 September 3rd, 2007 08:52 AM
How to use the datediff function to compare dates cesemj VB How-To 0 June 9th, 2006 04:03 PM
How do I compare 2 dates? Lucy Classic ASP Basics 1 May 3rd, 2005 07:24 PM
Compare dates langer123 Classic ASP Basics 2 April 16th, 2005 08:57 AM
Compare Dates in JS apd8x Javascript 4 June 16th, 2003 08:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.