How to Convert a String Into a Date Format

How to Convert a String Into a Date Format thumbnail
Date functions make it easy to calculate date values.

Converting strings to other formats such as dates is a common requirement for web programmers. Converting a string to a date allows the developer to manipulate the values using internal date functions in Visual Basic. For instance, a developer who converts a string to a date can add days, months or years to a date. The date is added to the variable and the correct day of the week is calculated. Converting dates can be accomplished using the Visual Basic "Convert()" function.

Instructions

    • 1

      Open your Visual Basic project. Right-click the form and select "View Code." This opens the code-behind file for your form, which is where your conversion is completed.

    • 2

      Create your string variable and the variable used to assign the conversion. To create variables, use the following code:

      Dim myString as String
      Dim myDate as DateTime

    • 3

      Assign a string value to your variable. The following code assigns a string value to the variable:

      myString = "12/20/1975"

    • 4

      Convert the string to a date. The following code shows you how to make the actual conversion:

      myDate = Convert.ToDateTime(myString)

      The string is converted and the result is stored in the DateTime variable. This allows you to use the myDate variable with any of the date functions used in Visual Basic.

Related Searches:

References

  • Photo Credit calendar image by Aleksey Bakaleev from Fotolia.com

Comments

You May Also Like

Related Ads

Featured