Solved

Convert string to date

Posted on 2016-11-07
3
38 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 25

Expert Comment

by:Shaun Kline
Comment Utility
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 69

Expert Comment

by:Éric Moreau
Comment Utility
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 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now