Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 18th, 2004, 04:46 AM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Athens, , Greece.
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..
Reply With Quote
  #2 (permalink)  
Old August 18th, 2004, 08:20 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
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
Reply With Quote
  #3 (permalink)  
Old August 19th, 2004, 02:03 AM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Athens, , Greece.
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!]
Reply With Quote
  #4 (permalink)  
Old August 20th, 2004, 09:55 AM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Athens, , Greece.
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...
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:46 AM.


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