开发者

Visual basic script that control a date format

I would like to control a string if is in t开发者_StackOverflow社区he dd/mm/yyyy format and if the dd number is between 1 and 31 and if mm is between 1 and 12.


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.


You can use the DatePart function:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜