locked
convert string to date RRS feed

  • Question

  • User135331403 posted

    I need to convert this string "09122009" to a date 09/12/2009

    How do I do this in vb.net

    Thursday, August 27, 2009 3:08 PM

Answers

  • User-1267218547 posted

     Hi helixpoint,

    Try to check my code, I test it and it works fine for me.

    DateTime oldOrderDate = DateTime.ParseExact("09122009", "ddMMyyyy", System.Globalization.CultureInfo.CurrentCulture);
                string str = oldOrderDate.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                


    I hope it is helpful to you. If it doesn't answer for you, please feel free to let me know.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 31, 2009 2:28 AM

All replies

  • User1264447444 posted

     DateTime MyDateTime = DateTime.ParseExact(09122009,"dd/MM/yyyy",null)

    Thursday, August 27, 2009 4:00 PM
  • User-2119480821 posted
    Convert.ToDateTime("09122009").ToString("dd/MM/yyyy")
    Thursday, August 27, 2009 4:01 PM
  • User135331403 posted

    I get the same erroe. "The date is invalid" 

    Friday, August 28, 2009 8:18 AM
  • User-1507865547 posted

    DateTime MyDateTime = DateTime.ParseExact(09122009,"MMddyyyy",null)

    Friday, August 28, 2009 8:32 AM
  • User135331403 posted

    I still get "String was not recognized as a valid DateTime."

    Friday, August 28, 2009 10:24 AM
  • User-2119480821 posted
    Did u tried my post..
    Friday, August 28, 2009 11:52 AM
  • User244619866 posted

    try  

    Date dateObject = new Date(StringObject.Substring(5,4),StringObject.Substring(3,2), StringObject.Substring(1,2))

    Saturday, August 29, 2009 1:24 AM
  • User-2119480821 posted

    solution:

    Dim theCultureInfo As IFormatProvider = New System.Globalization.CultureInfo("en-GB", True)

    Dim theDateTime As DateTime = Convert.ToDateTime(DateTime.ParseExact("09122009", "ddMMyyyy", theCultureInfo)).ToString("dd/MM/yyyy")

    Saturday, August 29, 2009 4:35 AM
  • User1788218924 posted

    Use this :

    strDate="09122009"

    DateTime strNewDate = DateTime.Parse(strDate.ToString()).ToString("dd/MM/yyyy");



    Saturday, August 29, 2009 5:44 AM
  • User-1267218547 posted

     Hi helixpoint,

    Try to check my code, I test it and it works fine for me.

    DateTime oldOrderDate = DateTime.ParseExact("09122009", "ddMMyyyy", System.Globalization.CultureInfo.CurrentCulture);
                string str = oldOrderDate.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                


    I hope it is helpful to you. If it doesn't answer for you, please feel free to let me know.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 31, 2009 2:28 AM