Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vb.net convert non numeric date to numeric date

Posted on 2014-02-18
2
Medium Priority
?
321 Views
Last Modified: 2014-02-18
I couldn't find a lot of documentation on this.

I have a non standardized database that I am trying to tame.  I have a lot of dates in written format (July 3, 2013 ) for example.  I only want the month and year for this and I would like to automate this process.

What is the best way to take that string and convert it to a date format?
0
Comment
Question by:gwarcher
[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
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 39868964
You can use the standard DateTime.TryParse() method and pass in the English culture like below.  Then pass in your desired format to ToString() to get just the month/year:
        Dim en As New System.Globalization.CultureInfo("en-US")

        Dim strDateFromDatabase As String = "July 3, 2013"
        Dim dt As Date

        ' ... loop thru the database rows ...

            If DateTime.TryParse(strDateFromDatabase, en, Globalization.DateTimeStyles.None, dt) Then
                Dim strFormattedDate As String = dt.ToString("MMyyyy")
                MessageBox.Show(strFormattedDate)
                ' ... do something with "strFormattedDate" ...
            Else
                MessageBox.Show(strDateFromDatabase, "Error Parsing Date")
            End If

Open in new window

0
 

Author Closing Comment

by:gwarcher
ID: 39869399
thanks!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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