|
-
Aug 1st, 2008, 09:35 PM
#1
Thread Starter
Fanatic Member
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
-
Aug 1st, 2008, 11:13 PM
#2
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
-
Aug 2nd, 2008, 12:23 AM
#3
Re: Date Validation And Month
I would use this:
Code:
myDate = Date '-- or whatever date
MsgBox Day(DateSerial(Year(myDate), Month(myDate) + 1, 0))
-
Aug 2nd, 2008, 11:31 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|