0
Dim string_date As String 
string_date="31/03/2014"    

how to convert string_date to date in "dd/MM/yyyy" format to compare with current date

Kym NT
  • 670
  • 9
  • 28
sanket munj
  • 29
  • 1
  • 6
  • 1
    possible duplicate of [Convert a string to a date in vb](http://stackoverflow.com/questions/8634568/convert-a-string-to-a-date-in-vb) – bansi Nov 12 '13 at 04:49

2 Answers2

1

Use DateTime.TryParseExact():

    Dim string_date As String = "31/03/2014"
    Dim dt As DateTime
    If DateTime.TryParseExact(string_date, "dd/MM/yyyy", Nothing, Globalization.DateTimeStyles.None, dt) Then
        Debug.Print("dt = " & dt.ToString("D"))
        If dt.Equals(DateTime.Today) Then
            Debug.Print("Equal to Today")
        Else
            Debug.Print("Not Equal to Today")
        End If
    End If
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • not working properly . everytime control goes out of main if statemnt conversion from string to date is not working – sanket munj Nov 12 '13 at 08:10
  • 1
    When your inside the `If` statement, the conversion was successful. Nothing can be said about the outside of the `If` statement, though, without seeing the entirety of your code. Did the conversion fail?...or did you just exit the `If` portion?...I don't know. Show us your code up in the question area by editing it. – Idle_Mind Nov 12 '13 at 13:27
0

Finally, I got my own solution.

d1 as date
string_date as string
string_date="31/03/2014"
d1 = Date.ParseExact(string_date, "dd/MM/yyyy", Globalization.CultureInfo.InvariantCulture)
Pang
  • 9,564
  • 146
  • 81
  • 122
sanket munj
  • 29
  • 1
  • 6