simone
simone

Reputation: 811

Visual basic script that control a date format

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.

Upvotes: 0

Views: 438

Answers (3)

Buggabill
Buggabill

Reputation: 13901

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.

Upvotes: 1

Joel Coehoorn
Joel Coehoorn

Reputation: 415705

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.

Upvotes: 0

Joey
Joey

Reputation: 354456

You can use the DatePart function:

DatePart("m", date)
DatePart("d", date)

Upvotes: 0

Related Questions