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
Solved

vb.net convert non numeric date to numeric date

Posted on 2014-02-18
2
316 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
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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