Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format() doesn't seem to work

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
0
0
US
Format() or String.Format() doesn't seem to format any thing.

Example:
If curString = "12122006"
Format(curString, "M/d/yyyy") would return M/d/yyyy
String.Format(curString, "M/d/yyyy") would return 12122006

Basically Format returns whatever is in quotes for the style and String.Format returns whatever is in the string you were trying to format. WTF?

-I hate Microsoft!
-Forever and always forward.
 
That one I'm not worried about. They are entering the date off a printout. So if they are actually stupid enough to type the date in something else then paste it in there they deserve to get an error and I'll smack them. I'll check out that .TryParse. Never seen/hear of it before.

-I hate Microsoft!
-Forever and always forward.
 
Your String.Format command seems to be missing the place holder, try this.
Code:
String.Format("{0:M/d/yyyy}", curString)
You could also use the DateTimePicker control, which will not allow the user to insert an invalid date -or- you could use the DateTime class to attempt to parse the string to a valid date
Code:
Dim dt as DateTime
Try
     dt = DateTime.Parse(curString)
     curString = String.Format("{0:M/d/yyyy}", dt.Tostring)
Catch ex as Exception
     MessageBox.Show(String.Format("'{0}' is not a valid date", curString))
End Try

Maybe this world is another planet’s Hell.
Aldous Huxley

eyes_015.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top