O'Reilly logo

Visual Basic 2008 Recipes: A Problem-Solution Approach by Rakesh Rajan, Matthew MacDonald, Allen Jones, Todd Herman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.7. Create Dates and Times from Strings

Problem

You need to create a System.DateTime or System.DateTimeOffset instance that represents the time and date specified in a string.

Solution

Use the Parse/TryParse or ParseExact/TryParseExact methods of the DateTime or DateTimeOffset structure.

Many subtle issues are associated with using the DateTime and DateTimeOffset structures to represent dates and times in your applications. Although the Parse and ParseExact methods, as well as the TryParse and TryParseExact counterparts, create DateTime or DateTimeOffset objects from strings as described in this recipe, you must be careful how you use the resulting ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required