converting string to date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pvenkatesh2k4
    New Member
    • Feb 2008
    • 18

    converting string to date

    hi to all i need to convert string to date. it shows invalid string format for parsing
    here is my code:

    string s="13/07/07" //in dd/mm/yy format

    DateTime d=DateTime.Pars e(s) //actually system time is in mm/dd/yyyy format

    but this statement shows an error"String was not reconized as a valid Datetime"
    what i need to do? do i need to rearrange the string
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Hi,

    Yes, you have to rearrange the string in the format "MM/DD/YYYY".


    Balaji

    Comment

    • todashah
      New Member
      • Feb 2008
      • 26

      #3
      Dear Write down the following Code...
      First add name space Globalisation using

      using System.Globaliz ation;

      then to convert given string(31/12/2008) to a date write down following
      two line code.

      CultureInfo culture = new CultureInfo("en-GB");

      DateTime dt = Convert.ToDateT ime("31/12/2008",culture);

      Now 31/12/2008 which one pass a string now convert to date
      but this date is in mm/dd/yyyy format not in dd/mm/yyyy format.

      I hope this is useful to u...

      Bye.....Take Care.....Enjoy Coding

      Comment

      Working...