tags:

views:

128

answers:

3

Hi all,
i would like to control a string if is in the dd/mm/yyyy format and if the dd number is between 1 and 31 and if mm is between 1 and 12
Someone can help me?
thanks

A: 

You can use the DatePart function:

DatePart("m", date)
DatePart("d", date)
Joey
A: 

Wait what? Your question is not very clear. Do you have a DateTime and need to output it in a specific format? Are you accepting a string from the user and need to make sure it fits that format? Do you get a string from somewhere else that you need to match for a specific format?

Most of all, why do you care? You shouldn't be dealing with dates as strings, except at the point of interaction with the user or other data source. Inside your program they should be a DateTime type. Assuming you're 'vb.net' tag is correct, the DateTime has handy Parse, TryParse, and ParseExact, and TryParseExact static methods you can use to accept most anything the user could throw at you.

Joel Coehoorn
+1  A: 

In vb.net you can use the IsDate() function to test the validity of a date. This will insure that the day and the month are within the valid range.

Buggabill