Solved

Convert string to date

Posted on 2016-11-07
3
69 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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