3 Replies - 8602 Views - Last Post: 30 June 2011 - 02:48 AM Rate Topic: -----

#1 vbOrangeBoy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-June 11

How to convert date from "dd/MM/yyyy" to "MM/dd/yyyy"

Posted 28 June 2011 - 04:06 PM

Hi

I'm trying to read dates stored in a Excel sheet, but they are in this format "dd/MM/yyyy" and when I choose a date from MonthCalendar1 it's in "MM/dd/yyyy" format! so I can't compare them together .. I have to make them in the same format ..I get this error when I write this code: (Conversion from string "27/06/2011" to type 'Date' is not valid.)

My idea is to convert the "dd/MM/yyyy" to string and then to "MM/dd/yyyy"
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim DateA As Date = Format(CDate("27/06/2011"), "MM/dd/yyyy")
    End Sub


If I solved this one I could use the same way in my program. I think.
Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: How to convert date from "dd/MM/yyyy" to "MM/dd/yyyy"

#2 NavilShah   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 50
  • Joined: 02-November 10

Re: How to convert date from "dd/MM/yyyy" to "MM/dd/yyyy"

Posted 28 June 2011 - 08:20 PM

We can have a temporary solution to this problem

Dim strDate As String = "27/06/2011"
Dim daDate As Date = Date.Parse(strDate.Substring(3, 2) & "/" & strDate.Substring(0, 2) & "/" & strDate.Substring(6, 4))



or

we have to make 2 functions one which will convert any date format to yyyyMMdd and then convert it into user specified format....

or

we can change the monthcalender format to the format specific in excel sheet.....
Was This Post Helpful? 0
  • +
  • -

#3 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 666
  • Joined: 01-October 08

Re: How to convert date from "dd/MM/yyyy" to "MM/dd/yyyy"

Posted 29 June 2011 - 05:43 AM

MonthCalendar Dates are DateTime so once the string is converted to DateTime the comparison can be made.

        Dim sExcel As String = "29/06/2011"
        Dim provider As System.Globalization.CultureInfo = System.Globalization.CultureInfo.InvariantCulture
        Dim dExcel As DateTime = DateTime.ParseExact(sExcel, "dd/MM/yyyy", provider)

        'MonthCalendar dates are datetime
        If dExcel.Date = MonthCalendar1.Selectionstart.Date Then
            Stop
        End If


Was This Post Helpful? 0
  • +
  • -

#4 vbOrangeBoy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-June 11

Re: How to convert date from "dd/MM/yyyy" to "MM/dd/yyyy"

Posted 30 June 2011 - 02:48 AM

Thank you very much :) it works now in both ways!

This post has been edited by vbOrangeBoy: 30 June 2011 - 02:50 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1