Results 1 to 4 of 4

Thread: Convert string into DateTime

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Rep Power
    3

    Default Convert string into DateTime

    I am working one live project where I use asp.net as front end. I want to convert a string such as "YYYYMMDD" or "DDMMYYYY" in DateTime object. If you are having any suggestions then reply me. It can helpful to me.
    Here is my code:
    Code:
    using System; 
      using System. Collections. Generic; 
      using System. Text; 
      using System. Globalization; 
    
      namespace ConsoleApplication1 
      {
          class Program 
          {
              static void Main (string [] args) 
              {
                  string date = "051209"; 
                  DateTime datetest = new DateTime () ;
                  datetest = Parse (date); 
              }
          }
      }

  2. #2
    Join Date
    Sep 2009
    Posts
    53
    Rep Power
    3

    Default

    Try the following codeine. I use ParseExact property.

    Code:
    datetest = DateTime.ParseExact (date, "YYYYMMDD", null)

  3. #3
    Join Date
    Sep 2009
    Posts
    60
    Rep Power
    3

    Default

    I try this code line but unable to solve.it will give following error


    Error 1 The name 'ParseExact' does not exist in the current context D:EFBDEVtestConsoleApplication1ConsoleApplica tion1Program.cs 14 24 ConsoleApplication1

  4. #4
    Join Date
    Sep 2009
    Posts
    68
    Rep Power
    3

    Default

    Try the following code, this may help you.
    Code:
    string myDate = " text ";
    DateTimeFormatInfo dtfr = new DateTimeFormatInfo();
    dtfr.ShortDatePattern = "ddMMyyyy";
    DateTime d = DateTime.Parse(myDate,dtfr);

Similar Threads

  1. Convert string UPPERCASE to lowercase
    By RodríguezBrown in forum other peripherals
    Replies: 0
    Last Post: 08-16-2010, 01:35 PM
  2. Replies: 0
    Last Post: 10-06-2009, 10:11 AM
  3. DateTime.Parse(myString)
    By jazzlearner in forum Programming
    Replies: 0
    Last Post: 11-17-2008, 10:17 AM
  4. String
    By quckhil in forum Programming
    Replies: 0
    Last Post: 08-22-2008, 09:32 AM
  5. String
    By techno23 in forum Programming
    Replies: 0
    Last Post: 03-26-2008, 12:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48