View Single Post
Old Jan 11th, 2007, 7:56 AM   #4
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,125
Rep Power: 5 lectricpharaoh will become famous soon enough
The easiest way to accomplish something like this is to use DateTime from the System namespace. First you build the string from user input, then try to create a valid DateTime instance from it using DateTime.Parse(). This will return a valid object if successful, and otherwise, it will throw an exception. If you're not comfortable using exceptions, or wish to simplify the code, you can use DateTime.TryParse() instead. This will accept an out DateTime parameter (semantically, this is just a ref parameter that doesn't need to be initialized prior to the call), and it will return a bool to indicate whether it succeeded. If it returns true, that means that the DateTime parameter has been filled in with valid information; otherwise, the string you provided could not be converted to DateTime.

There are also a whole host of methods and properties of DateTime that you can use to display or process the information however you like.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is online now   Reply With Quote