Results 1 to 7 of 7

Thread: [RESOLVED] Check Date Format input

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Resolved [RESOLVED] Check Date Format input

    Hi

    I am taking a date input from a text box "txtdate.txt"

    Now that should be in the format "mm/dd/yy" else it should give a error msg box saying " Enter correct format "

    can any one help in writing this function??

    also if not complicated can i also verify that the month added is correct( between 1 and 12) and the date value also between 1 and 31 in the same function??

    thanks

  2. #2
    Member
    Join Date
    Jan 2007
    Posts
    36

    Re: Check Date Format input

    Use ToDate and IsDate function....

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Check Date Format input

    i never used these function.. could u show the code??

  4. #4
    Member
    Join Date
    Jan 2007
    Posts
    36

    Re: Check Date Format input

    CDate function can convert a string to date

    IsDate function checkes whether a string is date or not...


    check this link...

    http://msdn.microsoft.com/library/de...7d35c5d7ba.asp

  5. #5
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Check Date Format input

    Hmm...

    VB Code:
    1. Private Sub Command1_Click()
    2.     If IsDate(txtDate.Text) Then
    3.         MsgBox "Date Accepted"
    4.     Else
    5.         MsgBox "Please Enter the correct Format"
    6.     End If
    7. End Sub

  6. #6
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Check Date Format input

    Ok here is a much better version...

    VB Code:
    1. Dim boolDate As Boolean
    2.  
    3. Private Sub Command1_Click()
    4. boolDate = False
    5.     If IsDate(txtDate.Text) Then
    6.         If txtDate.Text Like Format("##/##/##", "mm/dd/yy") Then
    7.             MsgBox "Date Accepted"
    8.             boolDate = True
    9.         Else
    10.             boolDate = False
    11.         End If
    12.     Else
    13.         boolDate = False
    14.     End If
    15.    
    16.     If Not boolDate Then
    17.         MsgBox "Please Enter the correct Format"
    18.     End If
    19. End Sub

    I see you want to validate the date and the format as well. Hope it helps!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    139

    Re: Check Date Format input

    rep added

    thanks man.. will check it out.. looks pretty nice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width