Reputation: 685
I currently run an array which reads 6 or so lines from a text file. Below is an example of how i'm extracting the required information from the lines in the text file
line = allLines.Where(Function(x) (x.StartsWith("plandate="))).SingleOrDefault()
If line IsNot Nothing Then
AllDetails(numfiles).pDate = line.Split("="c)(1)
End If
In this instance I'm extracting the planned date in the format dd/MM/yy
For part of a sub I need to change the reference of the format from dd/MM/yy
to dd MMMM yy
.
I've tried the following
Dim uPland As String = AllDetails(n).pDate.ToString("dd MMMM yy")
however i get the following error message
Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.
The format needs to be changed as I folders which are created with dates as a title using the dd MMMM yy
format.
If anymore code is needed to be posted then please let me know
Any guidance please
Upvotes: 0
Views: 115
Reputation: 685
FYI I've managed to sort the issue using the following
Dim uPland As String = Date.Parse(AllDetails(n).pDate).ToString("dd MMMM yy")
Upvotes: 0
Reputation: 1503669
Currently you're never parsing the values as DateTime
values - which means you can't format them as DateTime
either. The only single-parameter ToString
method on String
is the one with IFormatProvider
as the parameter type, which is why you're getting the error you are.
I suggest you change the type of pDate
from String
to DateTime
, parse (e.g. using DateTime.ParseExact
) when you read the file, and then convert back to text in whatever format you're interested in only when you really need to do so.
Upvotes: 2