Solved

Convert string to date

Posted on 2016-11-07
3
57 Views
Last Modified: 2016-11-09
Hi,

in vb.net, 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
0
Comment
Question by:FCapo
3 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 41877781
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: https://msdn.microsoft.com/en-us/library/ms131044(v=vs.110).aspx
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41878072
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?
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 41879106
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"))
		Else
			Console.WriteLine("Failed to convert {0}", fr_Date_Field)
		End If
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG
-saige-
1

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question