Results 1 to 4 of 4

Thread: Date Validation And Month

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Date Validation And Month

    please some one tell me how to know that the date entered in a Textbox is valid or not.
    i m using this format 3/08/2008

    next question is how to know how many days are there in a given month and how to start a next month when we close the current month

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Date Validation And Month

    isdate(text1.text)

    there may well be a better way to get the number of days in a month, but this should work
    Code:
    msgbox day(dateadd("d",-1,dateadd("m",1,"1/" & format(text1, "mmm") & "/" & year(text1))))
    Last edited by westconn1; Aug 1st, 2008 at 11:30 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Date Validation And Month

    I would use this:
    Code:
       myDate = Date '-- or whatever date
       MsgBox Day(DateSerial(Year(myDate), Month(myDate) + 1, 0))
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Date Validation And Month

    It would be a much better idea (in terms of amount of code, reliability, etc) to not use a Textbox at all, but a proper date control instead - like the ones shown in the article What controls can I use to input a date/time? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

    You may also find it useful to read the FAQ article Why are my dates not working properly?, which explains things like the big differences between a Date and a String.

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