Convert string to date


in, I have a column with some dates in string format, they are in french and they only have the month and the day, such as "12 octobre", is there a way that I can convert these strings into date format?

Thank you
Who is Participating?
it_saigeConnect With a Mentor DeveloperCommented:
Actually it should, you have to ensure that you pass the specific culture information.

Proof of concept -
Imports System.Globalization

Module Module1
	Sub Main()
		Dim fr_Date_Field = "12 octobre"
		Dim converted As Date
		If Date.TryParseExact(fr_Date_Field, "dd MMMM", New CultureInfo("fr-FR"), Globalization.DateTimeStyles.None, converted) Then
			Console.WriteLine("Successfully converted {0} to {1}", fr_Date_Field, converted.ToString("MM/dd"))
			Console.WriteLine("Failed to convert {0}", fr_Date_Field)
		End If
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG
Shaun KlineLead Software EngineerCommented:
The TryParseExact method of the Date object may be what you are looking for. Here is the link to Microsoft's description of this function:
Éric MoreauSenior .Net ConsultantCommented:
not sure that the month name in French will parse correctly. I would create a method that would take the word right of the space and build "select case" to find out the month.

Then you take what is left of the space and that becomes your day.

Now it you want to build a date from it, you will need a year. What will you put?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.